

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/Mine.jpg">
  <link rel="icon" href="/img/Mine.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Chiam">
  <meta name="keywords" content="算法，安全">
  
    <meta name="description" content="『C++&amp;C 语言』C 语言入门经典题目及其答案 写在开始：   我叫风骨散人，名字的意思是我多想可以不低头的自由生活，可现实却不是这样。家境贫寒，总得向这个世界低头，所以我一直在奋斗，想改变我的命运给亲人好的生活，希望同样被生活绑架的你可以通过自己的努力改变现状，深知成年人的世界里没有容易二字。目前是一名在校大学生，预计考研，热爱编程，热爱技术，喜欢分享，知识无界，希望我的分享可以帮到你">
<meta property="og:type" content="article">
<meta property="og:title" content="『C++&amp;C语言』C语言入门经典题目及其答案">
<meta property="og:url" content="http://example.com/2023/12/06/%E3%80%8EC++&C%E8%AF%AD%E8%A8%80%E3%80%8FC%E8%AF%AD%E8%A8%80%E5%85%A5%E9%97%A8%E7%BB%8F%E5%85%B8%E9%A2%98%E7%9B%AE%E5%8F%8A%E5%85%B6%E7%AD%94%E6%A1%88/index.html">
<meta property="og:site_name" content="Chiam 的个人主页">
<meta property="og:description" content="『C++&amp;C 语言』C 语言入门经典题目及其答案 写在开始：   我叫风骨散人，名字的意思是我多想可以不低头的自由生活，可现实却不是这样。家境贫寒，总得向这个世界低头，所以我一直在奋斗，想改变我的命运给亲人好的生活，希望同样被生活绑架的你可以通过自己的努力改变现状，深知成年人的世界里没有容易二字。目前是一名在校大学生，预计考研，热爱编程，热爱技术，喜欢分享，知识无界，希望我的分享可以帮到你">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-12-05T16:11:43.635Z">
<meta property="article:modified_time" content="2023-12-05T16:17:41.557Z">
<meta property="article:author" content="Chiam">
<meta property="article:tag" content="算法，安全">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>『C++&amp;C语言』C语言入门经典题目及其答案 - Chiam 的个人主页</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/css/custom.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"❡"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Chiam&#39;s Blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="『C++&amp;C语言』C语言入门经典题目及其答案"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-12-06 00:11" pubdate>
          2023年12月6日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          42k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          354 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">『C++&amp;C语言』C语言入门经典题目及其答案</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="『C-C-语言』C-语言入门经典题目及其答案"><a href="#『C-C-语言』C-语言入门经典题目及其答案" class="headerlink" title="『C++&amp;C 语言』C 语言入门经典题目及其答案"></a>『C++&amp;C 语言』C 语言入门经典题目及其答案</h1><blockquote>
<p><strong>写在开始：</strong></p>
</blockquote>
<blockquote>
<p>我叫风骨散人，名字的意思是我多想可以<code>不低头的自由生活</code>，可现实却不是这样。家境贫寒，总得向这个世界低头，所以我一直在奋斗，想<code>改变我的命运</code>给亲人好的生活，希望<code>同样被生活绑架的你</code>可以通过自己的努力改变现状，深知成年人的世界里没有容易二字。目前是一名在校大学生，预计考研，热爱编程，热爱技术，喜欢分享，知识无界，希望我的分享可以帮到你！<br>如果有什么想看的，可以私信我，如果在能力范围内，我会发布相应的博文！<br>感谢大家的阅读！😘 你的点赞、收藏、关注是对我最大的鼓励！</p>
</blockquote>
<p>【程序 1】<br>题目：有 1、2、3、4 个数字，能组成多少个互不相同且无重复数字的三位数？都是多少？ 1.程序分析：可填在百位、十位、个位的数字都是 1、2、3、4。组成所有的排列后再去<br>掉不满足条件的排列。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs java">main() &#123;<br><span class="hljs-type">int</span> i,j,k;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;<span class="hljs-number">5</span>;i++) ／*以下为三重循环*/<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">1</span>;j&lt;<span class="hljs-number">5</span>;j++)<br><span class="hljs-keyword">for</span> (k=<span class="hljs-number">1</span>;k&lt;<span class="hljs-number">5</span>;k++) &#123;<br><span class="hljs-keyword">if</span> (i!=k&amp;&amp;i!=j&amp;&amp;j!=k) <span class="hljs-comment">/*确保i、j、k三位互不相同*/</span><br>printf(<span class="hljs-string">&quot;%d,%d,%d\n&quot;</span>,i,j,k); &#125;&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 2】<br>题目：企业发放的奖金根据利润提成。利润(I)低于或等于 10 万元时，奖金可提 10%；利润高<br>于 10 万元，低于 20 万元时，低于 10 万元的部分按 10%提成，高于 10 万元的部分，可可提<br>成 7.5%；20 万到 40 万之间时，高于 20 万元的部分，可提成 5%；40 万到 60 万之间时高于<br>40 万元的部分，可提成 3%；60 万到 100 万之间时，高于 60 万元的部分，可提成 1.5%，高于<br>100 万元时，超过 100 万元的部分按 1%提成，从键盘输入当月利润 I，求应发放奖金总数？ 1.程序分析：请利用数轴来分界，定位。注意定义时需把奖金定义成长整型。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java">main() &#123;<br><span class="hljs-type">long</span> <span class="hljs-type">int</span> i;<br><span class="hljs-type">int</span> bonus1,bonus2,bonus4,bonus6,bonus10,bonus;<br>scanf(<span class="hljs-string">&quot;%ld&quot;</span>,&amp;i);<br>bonus1=<span class="hljs-number">100000</span>*<span class="hljs-number">0.1</span>;bonus2=bonus1+<span class="hljs-number">100000</span>*<span class="hljs-number">0.75</span>;<br>bonus4=bonus2+<span class="hljs-number">200000</span>*<span class="hljs-number">0.5</span>;<br>bonus6=bonus4+<span class="hljs-number">200000</span>*<span class="hljs-number">0.3</span>;<br>bonus10=bonus6+<span class="hljs-number">400000</span>*<span class="hljs-number">0.15</span>;<br><span class="hljs-keyword">if</span>(i&lt;=<span class="hljs-number">100000</span>)<br>bonus=i*<span class="hljs-number">0.1</span>;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i&lt;=<span class="hljs-number">200000</span>)<br>bonus=bonus1+(i-<span class="hljs-number">100000</span>)*<span class="hljs-number">0.075</span>;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i&lt;=<span class="hljs-number">400000</span>)<br>bonus=bonus2+(i-<span class="hljs-number">200000</span>)*<span class="hljs-number">0.05</span>;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i&lt;=<span class="hljs-number">600000</span>)<br>bonus=bonus4+(i-<span class="hljs-number">400000</span>)*<span class="hljs-number">0.03</span>;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i&lt;=<span class="hljs-number">1000000</span>)<br>bonus=bonus6+(i-<span class="hljs-number">600000</span>)*<span class="hljs-number">0.015</span>;<br><span class="hljs-keyword">else</span><br>bonus=bonus10+(i-<span class="hljs-number">1000000</span>)*<span class="hljs-number">0.01</span>;<br>printf(<span class="hljs-string">&quot;bonus=%d&quot;</span>,bonus); &#125;<br></code></pre></td></tr></table></figure>

<p>【程序 3】<br>题目：一个整数，它加上 100 后是一个完全平方数，再加上 168 又是一个完全平方数，请问该数是多少？ 1.程序分析：在 10 万以内判断，先将该数加上 100 后再开方，再将该数加上 268 后再开方，如果开方后<br>的结果满足如下条件，即是结果。请看具体分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;math.h&quot;</span><br>main() &#123;<br><span class="hljs-type">long</span> <span class="hljs-type">int</span> i,x,y,z;<br><span class="hljs-keyword">for</span> (i=<span class="hljs-number">1</span>;i&lt;<span class="hljs-number">100000</span>;i++)<br>&#123; x=sqrt(i+<span class="hljs-number">100</span>); <span class="hljs-comment">/*x为加上100后开方后的结果*/</span><br>y=sqrt(i+<span class="hljs-number">268</span>); <span class="hljs-comment">/*y为再加上168后开方后的结果*/</span><br><span class="hljs-keyword">if</span>(x*x==i+<span class="hljs-number">100</span>&amp;&amp;y*y==i+<span class="hljs-number">268</span>)<span class="hljs-comment">/*如果一个数的平方根的平方等于该数，这说明此数是完全平方数*/</span><br>printf(<span class="hljs-string">&quot;\n%ld\n&quot;</span>,i); &#125; &#125;<br></code></pre></td></tr></table></figure>

<p>【程序 4】<br>题目：输入某年某月某日，判断这一天是这一年的第几天？ 1.程序分析：以 3 月 5 日为例，应该先把前两个月的加起来，然后再加上 5 天即本年的第几天，特殊<br>情况，闰年且输入月份大于 3 时需考虑多加一天。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs java">main() &#123;<br><span class="hljs-type">int</span> day,month,year,sum,leap;<br>printf(<span class="hljs-string">&quot;\nplease input year,month,day\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d,%d,%d&quot;</span>,&amp;year,&amp;month,&amp;day);<br><span class="hljs-keyword">switch</span>(month)<span class="hljs-comment">/*先计算某月以前月份的总天数*/</span><br>&#123; <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:sum=<span class="hljs-number">0</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:sum=<span class="hljs-number">31</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:sum=<span class="hljs-number">59</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:sum=<span class="hljs-number">90</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">5</span>:sum=<span class="hljs-number">120</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">6</span>:sum=<span class="hljs-number">151</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">7</span>:sum=<span class="hljs-number">181</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">8</span>:sum=<span class="hljs-number">212</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">9</span>:sum=<span class="hljs-number">243</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">10</span>:sum=<span class="hljs-number">273</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">11</span>:sum=<span class="hljs-number">304</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-number">12</span>:sum=<span class="hljs-number">334</span>;<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">default</span>:printf(<span class="hljs-string">&quot;data error&quot;</span>);<span class="hljs-keyword">break</span>; &#125;<br>sum=sum+day; <span class="hljs-comment">/*再加上某天的天数*/</span><br><span class="hljs-keyword">if</span>(year%<span class="hljs-number">400</span>==<span class="hljs-number">0</span>||(year%<span class="hljs-number">4</span>==<span class="hljs-number">0</span>&amp;&amp;year%<span class="hljs-number">100</span>!=<span class="hljs-number">0</span>))<span class="hljs-comment">/*判断是不是闰年*/</span><br>leap=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">else</span><br>leap=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">if</span>(leap==<span class="hljs-number">1</span>&amp;&amp;month&gt;<span class="hljs-number">2</span>)<span class="hljs-comment">/*如果是闰年且月份大于2,总天数应该加一天*/</span><br>sum++;<br>printf(<span class="hljs-string">&quot;It is the %dth day.&quot;</span>,sum);&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 5】<br>题目：输入三个整数 x,y,z，请把这三个数由小到大输出。 1.程序分析：我们想办法把最小的数放到 x 上，先将 x 与 y 进行比较，如果 x&gt;y 则将 x 与 y 的值进行交换，<br>然后再用 x 与 z 进行比较，如果 x&gt;z 则将 x 与 z 的值进行交换，这样能使 x 最小。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java">main() &#123;<br><span class="hljs-type">int</span> x,y,z,t;<br>scanf(<span class="hljs-string">&quot;%d%d%d&quot;</span>,&amp;x,&amp;y,&amp;z);<br><span class="hljs-keyword">if</span> (x&gt;y)<br>&#123;t=x;x=y;y=t;&#125; <span class="hljs-comment">/*交换x,y的值*/</span><br><span class="hljs-keyword">if</span>(x&gt;z)<br>&#123;t=z;z=x;x=t;&#125;<span class="hljs-comment">/*交换x,z的值*/</span><br><span class="hljs-keyword">if</span>(y&gt;z)<br>&#123;t=y;y=z;z=t;&#125;<span class="hljs-comment">/*交换z,y的值*/</span><br>printf(<span class="hljs-string">&quot;small to big: %d %d %d\n&quot;</span>,x,y,z); &#125;<br></code></pre></td></tr></table></figure>

<p>【程序 6】<br>题目：用<em>号输出字母 C 的图案。 1.程序分析：可先用’</em>‘号在纸上写出字母 C，再分行输出。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main() &#123;<br>printf(<span class="hljs-string">&quot;Hello C-world!\n&quot;</span>);<br>printf(<span class="hljs-string">&quot; ****\n&quot;</span>);<br>printf(<span class="hljs-string">&quot; *\n&quot;</span>);<br>printf(<span class="hljs-string">&quot; * \n&quot;</span>);<br>printf(<span class="hljs-string">&quot; ****\n&quot;</span>); &#125;<br></code></pre></td></tr></table></figure>

<p>【程序 7】<br>题目：输出特殊图案，请在 c 环境中运行，看一看，Very Beautiful! 1.程序分析：字符共有 256 个。不同字符，图形不一样。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">char</span> a=<span class="hljs-number">176</span>,b=<span class="hljs-number">219</span>;<br>printf(<span class="hljs-string">&quot;%c%c%c%c%c\n&quot;</span>,b,a,a,a,b);<br>printf(<span class="hljs-string">&quot;%c%c%c%c%c\n&quot;</span>,a,b,a,b,a);<br>printf(<span class="hljs-string">&quot;%c%c%c%c%c\n&quot;</span>,a,a,b,a,a);<br>printf(<span class="hljs-string">&quot;%c%c%c%c%c\n&quot;</span>,a,b,a,b,a);<br>printf(<span class="hljs-string">&quot;%c%c%c%c%c\n&quot;</span>,b,a,a,a,b);&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 8】<br>题目：输出 9*9 口诀。 1.程序分析：分行与列考虑，共 9 行 9 列，i 控制行，j 控制列。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j,result;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span> (i=<span class="hljs-number">1</span>;i&lt;<span class="hljs-number">10</span>;i++)<br>&#123; <span class="hljs-keyword">for</span>(j=<span class="hljs-number">1</span>;j&lt;<span class="hljs-number">10</span>;j++)<br>&#123;<br>result=i*j;<br>printf(<span class="hljs-string">&quot;%d*%d=%-3d&quot;</span>,i,j,result);<span class="hljs-comment">/*-3d表示左对齐，占3位*/</span><br>&#125;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<span class="hljs-comment">/*每一行后换行*/</span><br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 9】<br>题目：要求输出国际象棋棋盘。 1.程序分析：用 i 控制行，j 来控制列，根据 i+j 的和的变化来控制输出黑方格，还是白方格。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">8</span>;i++)<br>&#123;<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;<span class="hljs-number">8</span>;j++)<br><span class="hljs-keyword">if</span>((i+j)%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>)<br>printf(<span class="hljs-string">&quot;%c%c&quot;</span>,<span class="hljs-number">219</span>,<span class="hljs-number">219</span>);<br><span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot; &quot;</span>);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 10】<br>题目：打印楼梯，同时在楼梯上方打印两个笑脸。 1.程序分析：用 i 控制行，j 来控制列，j 根据 i 的变化来控制输出黑方格的个数。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j;<br>printf(<span class="hljs-string">&quot;\1\1\n&quot;</span>);<span class="hljs-comment">/*输出两个笑脸*/</span><br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;<span class="hljs-number">11</span>;i++)<br>&#123;<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">1</span>;j&lt;=i;j++)<br>printf(<span class="hljs-string">&quot;%c%c&quot;</span>,<span class="hljs-number">219</span>,<span class="hljs-number">219</span>);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 11】<br>题目：古典问题：有一对兔子，从出生后第 3 个月起每个月都生一对兔子，小兔子长到第三个月<br>后每个月又生一对兔子，假如兔子都不死，问每个月的兔子总数为多少？ 1.程序分析： 兔子的规律为数列 1,1,2,3,5,8,13,21…. 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">long</span> f1,f2;<br><span class="hljs-type">int</span> i;<br>f1=f2=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;=<span class="hljs-number">20</span>;i++)<br>&#123; printf(<span class="hljs-string">&quot;%12ld %12ld&quot;</span>,f1,f2);<br><span class="hljs-keyword">if</span>(i%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot;\n&quot;</span>);<span class="hljs-comment">/*控制输出，每行四个*/</span><br>f1=f1+f2; <span class="hljs-comment">/*前两个月加起来赋值给第三个月*/</span><br>f2=f1+f2; <span class="hljs-comment">/*前两个月加起来赋值给第三个月*/</span><br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 12】<br>题目：判断 101-200 之间有多少个素数，并输出所有素数。 1.程序分析：判断素数的方法：用一个数分别去除 2 到 sqrt(这个数)，如果能被整除，<br>则表明此数不是素数，反之是素数。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;math.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> m,i,k,h=<span class="hljs-number">0</span>,leap=<span class="hljs-number">1</span>;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(m=<span class="hljs-number">101</span>;m&lt;=<span class="hljs-number">200</span>;m++)<br>&#123; k=sqrt(m+<span class="hljs-number">1</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>;i&lt;=k;i++)<br><span class="hljs-keyword">if</span>(m%i==<span class="hljs-number">0</span>)<br>&#123;leap=<span class="hljs-number">0</span>;<span class="hljs-keyword">break</span>;&#125;<br><span class="hljs-keyword">if</span>(leap) &#123;printf(<span class="hljs-string">&quot;%-4d&quot;</span>,m);h++;<br><span class="hljs-keyword">if</span>(h%<span class="hljs-number">10</span>==<span class="hljs-number">0</span>)<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>leap=<span class="hljs-number">1</span>;<br>&#125;<br>printf(<span class="hljs-string">&quot;\nThe total is %d&quot;</span>,h);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 13】<br>题目：打印出所有的“水仙花数”，所谓“水仙花数”是指一个三位数，其各位数字立方和等于该数<br>本身。例如：153 是一个“水仙花数”，因为 153&#x3D;1 的三次方＋ 5 的三次方＋ 3 的三次方。 1.程序分析：利用 for 循环控制 100-999 个数，每个数分解出个位，十位，百位。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> i,j,k,n;<br>printf(<span class="hljs-string">&quot;&#x27;water flower&#x27;number is:&quot;</span>);<br><span class="hljs-keyword">for</span>(n=<span class="hljs-number">100</span>;n&lt;<span class="hljs-number">1000</span>;n++)<br>&#123;<br>i=n/<span class="hljs-number">100</span>;<span class="hljs-comment">/*分解出百位*/</span><br>j=n/<span class="hljs-number">10</span>%<span class="hljs-number">10</span>;<span class="hljs-comment">/*分解出十位*/</span><br>k=n%<span class="hljs-number">10</span>;<span class="hljs-comment">/*分解出个位*/</span><br><span class="hljs-keyword">if</span>(i*<span class="hljs-number">100</span>+j*<span class="hljs-number">10</span>+k==i*i*i+j*j*j+k*k*k)<br>&#123;<br>printf(<span class="hljs-string">&quot;%-5d&quot;</span>,n);<br>&#125;<br>&#125;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 14】<br>题目：将一个正整数分解质因数。例如：输入 90,打印出 90&#x3D;2<em>3</em>3*5。</p>
<p>程序分析：对 n 进行分解质因数，应先找到一个最小的质数 k，然后按下述步骤完成：<br>(1)如果这个质数恰等于 n，则说明分解质因数的过程已经结束，打印出即可。<br>(2)如果 n&lt;&gt;k，但 n 能被 k 整除，则应打印出 k 的值，并用 n 除以 k 的商,作为新的正整数你 n,<br>重复执行第一步。<br>(3)如果 n 不能被 k 整除，则用 k+1 作为 k 的值,重复执行第一步。</p>
<p>2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><br>main()<br>&#123;<br><span class="hljs-type">int</span> n,i;<br>printf(<span class="hljs-string">&quot;\nplease input a number:\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;n);<br>printf(<span class="hljs-string">&quot;%d=&quot;</span>,n);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>;i&lt;=n;i++)<br>&#123;<br><span class="hljs-keyword">while</span>(n!=i)<br>&#123;<br><span class="hljs-keyword">if</span>(n%i==<span class="hljs-number">0</span>)<br>&#123; printf(<span class="hljs-string">&quot;%d*&quot;</span>,i);<br>n=n/i;<br>&#125;<br><span class="hljs-keyword">else</span><br><span class="hljs-keyword">break</span>;<br>&#125;<br>&#125;<br>printf(<span class="hljs-string">&quot;%d&quot;</span>,n);&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 15】<br>题目：利用条件运算符的嵌套来完成此题：学习成绩&gt;&#x3D;90 分的同学用 A 表示，60-89 分之间的用 B 表示，<br>60 分以下的用 C 表示。 1.程序分析：(a&gt;b)?a:b 这是条件运算符的基本例子。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> score;<br><span class="hljs-type">char</span> grade;<br>printf(<span class="hljs-string">&quot;please input a score\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;score);<br>grade=score&gt;=<span class="hljs-number">90</span>?<span class="hljs-string">&#x27;A&#x27;</span>:(score&gt;=<span class="hljs-number">60</span>?<span class="hljs-string">&#x27;B&#x27;</span>:<span class="hljs-string">&#x27;C&#x27;</span>);<br>printf(<span class="hljs-string">&quot;%d belongs to %c&quot;</span>,score,grade);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 16】<br>题目：输入两个正整数 m 和 n，求其最大公约数和最小公倍数。<br>1.程序分析：利用辗除法。</p>
<p>2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> a,b,num1,num2,temp;<br>printf(<span class="hljs-string">&quot;please input two numbers:\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d,%d&quot;</span>,&amp;num1,&amp;num2);<br><span class="hljs-keyword">if</span>(num1 &#123; temp=num1;<br>num1=num2;<br>num2=temp;<br>&#125;<br>a=num1;b=num2;<br><span class="hljs-keyword">while</span>(b!=<span class="hljs-number">0</span>)<span class="hljs-comment">/*利用辗除法，直到b为0为止*/</span><br>&#123;<br>temp=a%b;<br>a=b;<br>b=temp;<br>&#125;<br>printf(<span class="hljs-string">&quot;gongyueshu:%d\n&quot;</span>,a);<br>printf(<span class="hljs-string">&quot;gongbeishu:%d\n&quot;</span>,num1*num2/a);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 17】<br>题目：输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。 1.程序分析：利用 while 语句,条件为输入的字符不为’\n’.</p>
<p>2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">char</span> c;<br><span class="hljs-type">int</span> letters=<span class="hljs-number">0</span>,space=<span class="hljs-number">0</span>,digit=<span class="hljs-number">0</span>,others=<span class="hljs-number">0</span>;<br>printf(<span class="hljs-string">&quot;please input some characters\n&quot;</span>);<br><span class="hljs-keyword">while</span>((c=getchar())!=<span class="hljs-string">&#x27;\n&#x27;</span>)<br>&#123;<br><span class="hljs-keyword">if</span>(c&gt;=<span class="hljs-string">&#x27;a&#x27;</span>&amp;&amp;c&lt;=<span class="hljs-string">&#x27;z&#x27;</span>||c&gt;=<span class="hljs-string">&#x27;A&#x27;</span>&amp;&amp;c&lt;=<span class="hljs-string">&#x27;Z&#x27;</span>)<br>letters++;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(c==<span class="hljs-string">&#x27; &#x27;</span>)<br>space++;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(c&gt;=<span class="hljs-string">&#x27;0&#x27;</span>&amp;&amp;c&lt;=<span class="hljs-string">&#x27;9&#x27;</span>)<br>digit++;<br><span class="hljs-keyword">else</span><br>others++;<br>&#125;<br>printf(<span class="hljs-string">&quot;all in all:char=%d space=%d digit=%d others=%d\n&quot;</span>,letters,<br>space,digit,others);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 18】<br>题目：求 s&#x3D;a+aa+aaa+aaaa+aa…a 的值，其中 a 是一个数字。例如 2+22+222+2222+22222(此时<br>共有 5 个数相加)，几个数相加有键盘控制。 1.程序分析：关键是计算出每一项的值。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> a,n,count=<span class="hljs-number">1</span>;<br><span class="hljs-type">long</span> <span class="hljs-type">int</span> sn=<span class="hljs-number">0</span>,tn=<span class="hljs-number">0</span>;<br>printf(<span class="hljs-string">&quot;please input a and n\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d,%d&quot;</span>,&amp;a,&amp;n);<br>printf(<span class="hljs-string">&quot;a=%d,n=%d\n&quot;</span>,a,n);<br><span class="hljs-keyword">while</span>(count&lt;=n)<br>&#123;<br>tn=tn+a;<br>sn=sn+tn;<br>a=a*<span class="hljs-number">10</span>;<br>++count;<br>&#125;<br>printf(<span class="hljs-string">&quot;a+aa+...=%ld\n&quot;</span>,sn);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 19】<br>题目：一个数如果恰好等于它的因子之和，这个数就称为“完数”。例如 6&#x3D;1 ＋ 2 ＋ 3.编程<br>找出 1000 以内的所有完数。</p>
<ol>
<li>程序分析：请参照程序&lt;–上页程序 14. 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-keyword">static</span> <span class="hljs-type">int</span> k[<span class="hljs-number">10</span>];<br><span class="hljs-type">int</span> i,j,n,s;<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">2</span>;j&lt;<span class="hljs-number">1000</span>;j++)<br>&#123;<br>n=-<span class="hljs-number">1</span>;<br>s=j;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i &#123;<br><span class="hljs-keyword">if</span>((j%i)==<span class="hljs-number">0</span>)<br>&#123; n++;<br>s=s-i;<br>k[n]=i;<br>&#125;<br>&#125;<br><span class="hljs-keyword">if</span>(s==<span class="hljs-number">0</span>)<br>&#123;<br>printf(<span class="hljs-string">&quot;%d is a wanshu&quot;</span>,j);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i <span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%d,&quot;</span>,k[i])</span>;<br>printf(<span class="hljs-string">&quot;%d\n&quot;</span>,k[n]);<br>&#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 20】<br>题目：一球从 100 米高度自由落下，每次落地后反跳回原高度的一半；再落下，求它在<br>第 10 次落地时，共经过多少米？第 10 次反弹多高？ 1.程序分析：见下面注释 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">float</span> sn=<span class="hljs-number">100.0</span>,hn=sn/<span class="hljs-number">2</span>;<br><span class="hljs-type">int</span> n;<br><span class="hljs-keyword">for</span>(n=<span class="hljs-number">2</span>;n&lt;=<span class="hljs-number">10</span>;n++)<br>&#123;<br>sn=sn+<span class="hljs-number">2</span>*hn;<span class="hljs-comment">/*第n次落地时共经过的米数*/</span><br>hn=hn/<span class="hljs-number">2</span>; <span class="hljs-comment">/*第n次反跳高度*/</span><br>&#125;<br>printf(<span class="hljs-string">&quot;the total of road is %f\n&quot;</span>,sn);<br>printf(<span class="hljs-string">&quot;the tenth is %f meter\n&quot;</span>,hn);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 21】<br>题目：猴子吃桃问题：猴子第一天摘下若干个桃子，当即吃了一半，还不瘾，又多吃了一个<br>　　　第二天早上又将剩下的桃子吃掉一半，又多吃了一个。以后每天早上都吃了前一天剩下<br>　　　的一半零一个。到第 10 天早上想再吃时，见只剩下一个桃子了。求第一天共摘了多少。 1.程序分析：采取逆向思维的方法，从后往前推断。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> day,x1,x2;<br>day=<span class="hljs-number">9</span>;<br>x2=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">while</span>(day&gt;<span class="hljs-number">0</span>)<br>　&#123;x1=(x2+<span class="hljs-number">1</span>)*<span class="hljs-number">2</span>;<span class="hljs-comment">/*第一天的桃子数是第2天桃子数加1后的2倍*/</span><br>　x2=x1;<br>　day--;<br>　&#125;<br>printf(<span class="hljs-string">&quot;the total is %d\n&quot;</span>,x1);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 22】<br>题目：两个乒乓球队进行比赛，各出三人。甲队为 a,b,c 三人，乙队为 x,y,z 三人。已抽签决定<br>　　　比赛名单。有人向队员打听比赛的名单。a 说他不和 x 比，c 说他不和 x,z 比，请编程序找出<br>　　　三队赛手的名单。 1.程序分析：判断素数的方法：用一个数分别去除 2 到 sqrt(这个数)，如果能被整除，<br>　　　　　　则表明此数不是素数，反之是素数。 　　　　　　 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">char</span> i,j,k;<span class="hljs-comment">/*i是a的对手，j是b的对手，k是c的对手*/</span><br><span class="hljs-keyword">for</span>(i=<span class="hljs-string">&#x27;x&#x27;</span>;i&lt;=<span class="hljs-string">&#x27;z&#x27;</span>;i++)<br>　<span class="hljs-keyword">for</span>(j=<span class="hljs-string">&#x27;x&#x27;</span>;j&lt;=<span class="hljs-string">&#x27;z&#x27;</span>;j++)<br>　&#123;<br>　<span class="hljs-keyword">if</span>(i!=j)<br>　　<span class="hljs-keyword">for</span>(k=<span class="hljs-string">&#x27;x&#x27;</span>;k&lt;=<span class="hljs-string">&#x27;z&#x27;</span>;k++)<br>　　&#123; <span class="hljs-keyword">if</span>(i!=k&amp;&amp;j!=k)<br>　　　&#123; <span class="hljs-keyword">if</span>(i!=<span class="hljs-string">&#x27;x&#x27;</span>&amp;&amp;k!=<span class="hljs-string">&#x27;x&#x27;</span>&amp;&amp;k!=<span class="hljs-string">&#x27;z&#x27;</span>)<br>　　　printf(<span class="hljs-string">&quot;order is a--%c\tb--%c\tc--%c\n&quot;</span>,i,j,k);<br>　　　&#125;<br>　　&#125;<br>　&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 23】<br>题目：打印出如下图案（菱形）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java">   *<br>  ***<br> ******<br>********<br> ******<br>  ***<br>   *<br></code></pre></td></tr></table></figure>

<p>1.程序分析：先把图形分成两部分来看待，前四行一个规律，后三行一个规律，利用双重<br>　　　　　　 for 循环，第一层控制行，第二层控制列。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> i,j,k;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">3</span>;i++)<br>　&#123;<br>　<span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;=<span class="hljs-number">2</span>-i;j++)<br>　　printf(<span class="hljs-string">&quot; &quot;</span>);<br>　<span class="hljs-keyword">for</span>(k=<span class="hljs-number">0</span>;k&lt;=<span class="hljs-number">2</span>*i;k++)<br>　　printf(<span class="hljs-string">&quot;*&quot;</span>);<br>　printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>　&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">2</span>;i++)<br>　&#123;<br>　<span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;=i;j++)<br>　　printf(<span class="hljs-string">&quot; &quot;</span>);<br>　<span class="hljs-keyword">for</span>(k=<span class="hljs-number">0</span>;k&lt;=<span class="hljs-number">4</span>-<span class="hljs-number">2</span>*i;k++)<br>　　printf(<span class="hljs-string">&quot;*&quot;</span>);<br>　printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>　&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 24】<br>题目：有一分数序列：2&#x2F;1，3&#x2F;2，5&#x2F;3，8&#x2F;5，13&#x2F;8，21&#x2F;13…求出这个数列的前 20 项之和。 1.程序分析：请抓住分子与分母的变化规律。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> n,t,number=<span class="hljs-number">20</span>;<br><span class="hljs-type">float</span> a=<span class="hljs-number">2</span>,b=<span class="hljs-number">1</span>,s=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">for</span>(n=<span class="hljs-number">1</span>;n&lt;=number;n++)<br>　&#123;<br>　s=s+a/b;<br>　t=a;a=a+b;b=t;<span class="hljs-comment">/*这部分是程序的关键，请读者猜猜t的作用*/</span><br>　&#125;<br>printf(<span class="hljs-string">&quot;sum is %9.6f\n&quot;</span>,s);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 25】<br>题目：求 1+2!+3!+…+20!的和 1.程序分析：此程序只是把累加变成了累乘。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">float</span> n,s=<span class="hljs-number">0</span>,t=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">for</span>(n=<span class="hljs-number">1</span>;n&lt;=<span class="hljs-number">20</span>;n++)<br>　&#123;<br>　t*=n;<br>　s+=t;<br>　&#125;<br>printf(<span class="hljs-string">&quot;1+2!+3!...+20!=%e\n&quot;</span>,s);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 26】<br>题目：利用递归方法求 5!。 1.程序分析：递归公式：fn&#x3D;fn_1*4! 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i;<br><span class="hljs-type">int</span> <span class="hljs-title function_">fact</span><span class="hljs-params">()</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">5</span>;i++)<br>　printf(<span class="hljs-string">&quot;\40:%d!=%d\n&quot;</span>,i,fact(i));<br>&#125;<br><span class="hljs-type">int</span> <span class="hljs-title function_">fact</span><span class="hljs-params">(j)</span><br><span class="hljs-type">int</span> j;<br>&#123;<br><span class="hljs-type">int</span> sum;<br><span class="hljs-keyword">if</span>(j==<span class="hljs-number">0</span>)<br>　sum=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">else</span><br>　sum=j*fact(j-<span class="hljs-number">1</span>);<br><span class="hljs-keyword">return</span> sum;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 27】<br>题目：利用递归函数调用方式，将所输入的 5 个字符，以相反顺序打印出来。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i=<span class="hljs-number">5</span>;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">palin</span><span class="hljs-params">(<span class="hljs-type">int</span> n)</span>;<br>printf(<span class="hljs-string">&quot;\40:&quot;</span>);<br>palin(i);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">palin</span><span class="hljs-params">(n)</span><br><span class="hljs-type">int</span> n;<br>&#123;<br><span class="hljs-type">char</span> next;<br><span class="hljs-keyword">if</span>(n&lt;=<span class="hljs-number">1</span>)<br>　&#123;<br>　next=getchar();<br>　printf(<span class="hljs-string">&quot;\n\0:&quot;</span>);<br>　putchar(next);<br>　&#125;<br><span class="hljs-keyword">else</span><br>　&#123;<br>　next=getchar();<br>　palin(n-<span class="hljs-number">1</span>);<br>　putchar(next);<br>　&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 28】<br>题目：有 5 个人坐在一起，问第五个人多少岁？他说比第 4 个人大 2 岁。问第 4 个人岁数，他说比第<br>　　　 3 个人大 2 岁。问第三个人，又说比第 2 人大两岁。问第 2 个人，说比第一个人大两岁。最后<br>　　　问第一个人，他说是 10 岁。请问第五个人多大？ 1.程序分析：利用递归的方法，递归分为回推和递推两个阶段。要想知道第五个人岁数，需知道<br>　　　　　　第四人的岁数，依次类推，推到第一人（10 岁），再往回推。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">age(n)<br><span class="hljs-type">int</span> n;<br>&#123;<br><span class="hljs-type">int</span> c;<br><span class="hljs-keyword">if</span>(n==<span class="hljs-number">1</span>) c=<span class="hljs-number">10</span>;<br><span class="hljs-keyword">else</span> c=age(n-<span class="hljs-number">1</span>)+<span class="hljs-number">2</span>;<br><span class="hljs-keyword">return</span>(c);<br>&#125;<br>main()<br>&#123; printf(<span class="hljs-string">&quot;%d&quot;</span>,age(<span class="hljs-number">5</span>));<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 29】<br>题目：给一个不多于 5 位的正整数，要求：一、求它是几位数，二、逆序打印出各位数字。</p>
<ol>
<li>程序分析：学会分解出每一位数，如下解释：(这里是一种简单的算法，师专数 002 班赵鑫提供) 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">main( )<br>&#123;<br><span class="hljs-type">long</span> a,b,c,d,e,x;<br>scanf(<span class="hljs-string">&quot;%ld&quot;</span>,&amp;x);<br>a=x/<span class="hljs-number">10000</span>;<span class="hljs-comment">/*分解出万位*/</span><br>b=x%<span class="hljs-number">10000</span>/<span class="hljs-number">1000</span>;<span class="hljs-comment">/*分解出千位*/</span><br>c=x%<span class="hljs-number">1000</span>/<span class="hljs-number">100</span>;<span class="hljs-comment">/*分解出百位*/</span><br>d=x%<span class="hljs-number">100</span>/<span class="hljs-number">10</span>;<span class="hljs-comment">/*分解出十位*/</span><br>e=x%<span class="hljs-number">10</span>;<span class="hljs-comment">/*分解出个位*/</span><br><span class="hljs-keyword">if</span> (a!=<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot;there are 5, %ld %ld %ld %ld %ld\n&quot;</span>,e,d,c,b,a);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (b!=<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot;there are 4, %ld %ld %ld %ld\n&quot;</span>,e,d,c,b);<br>　　<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (c!=<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot; there are 3,%ld %ld %ld\n&quot;</span>,e,d,c);<br>　　　　<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (d!=<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot;there are 2, %ld %ld\n&quot;</span>,e,d);<br>　　　　　　<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (e!=<span class="hljs-number">0</span>) printf(<span class="hljs-string">&quot; there are 1,%ld\n&quot;</span>,e);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 30】<br>题目：一个 5 位数，判断它是不是回文数。即 12321 是回文数，个位与万位相同，十位与千位相同。　　　 1.程序分析：同 29 例 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java">main( )<br>&#123;<br><span class="hljs-type">long</span> ge,shi,qian,wan,x;<br>scanf(<span class="hljs-string">&quot;%ld&quot;</span>,&amp;x);<br>wan=x/<span class="hljs-number">10000</span>;<br>qian=x%<span class="hljs-number">10000</span>/<span class="hljs-number">1000</span>;<br>shi=x%<span class="hljs-number">100</span>/<span class="hljs-number">10</span>;<br>ge=x%<span class="hljs-number">10</span>;<br><span class="hljs-keyword">if</span> (ge==wan&amp;&amp;shi==qian)<span class="hljs-comment">/*个位等于万位并且十位等于千位*/</span><br>　printf(<span class="hljs-string">&quot;this number is a huiwen\n&quot;</span>);<br><span class="hljs-keyword">else</span><br>　printf(<span class="hljs-string">&quot;this number is not a huiwen\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 31】<br>题目：请输入星期几的第一个字母来判断一下是星期几，如果第一个字母一样，则继续<br>　　　判断第二个字母。 1.程序分析：用情况语句比较好，如果第一个字母一样，则判断用情况语句或 if 语句判断第二个字母。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123;<br><span class="hljs-type">char</span> letter;<br>printf(<span class="hljs-string">&quot;please input the first letter of someday\n&quot;</span>);<br><span class="hljs-keyword">while</span> ((letter=getch())!=<span class="hljs-string">&#x27;Y&#x27;</span>)<span class="hljs-comment">/*当所按字母为Y时才结束*/</span><br>&#123; <span class="hljs-keyword">switch</span> (letter)<br>&#123;<span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;S&#x27;</span>:printf(<span class="hljs-string">&quot;please input second letter\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">if</span>((letter=getch())==<span class="hljs-string">&#x27;a&#x27;</span>)<br>　　　　　　printf(<span class="hljs-string">&quot;saturday\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ((letter=getch())==<span class="hljs-string">&#x27;u&#x27;</span>)<br>　　　　　　　　　printf(<span class="hljs-string">&quot;sunday\n&quot;</span>);<br>　　　　　　　<span class="hljs-keyword">else</span> printf(<span class="hljs-string">&quot;data error\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;F&#x27;</span>:printf(<span class="hljs-string">&quot;friday\n&quot;</span>);<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;M&#x27;</span>:printf(<span class="hljs-string">&quot;monday\n&quot;</span>);<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;T&#x27;</span>:printf(<span class="hljs-string">&quot;please input second letter\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">if</span>((letter=getch())==<span class="hljs-string">&#x27;u&#x27;</span>)<br>　　　　　　printf(<span class="hljs-string">&quot;tuesday\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ((letter=getch())==<span class="hljs-string">&#x27;h&#x27;</span>)<br>　　　　　　　　　printf(<span class="hljs-string">&quot;thursday\n&quot;</span>);<br>　　　　　　　<span class="hljs-keyword">else</span> printf(<span class="hljs-string">&quot;data error\n&quot;</span>);<br>　　　　　<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;W&#x27;</span>:printf(<span class="hljs-string">&quot;wednesday\n&quot;</span>);<span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">default</span>: printf(<span class="hljs-string">&quot;data error\n&quot;</span>);<br>　　&#125;<br>　&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 32】<br>题目：Press any key to change color, do you want to try it. Please hurry up! 1.程序分析：　　　　　　　　　　　　 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br><span class="hljs-type">int</span> color;<br><span class="hljs-keyword">for</span> (color = <span class="hljs-number">0</span>; color &lt; <span class="hljs-number">8</span>; color++)<br>　&#123;<br>　textbackground(color);<span class="hljs-comment">/*设置文本的背景颜色*/</span><br>　cprintf(<span class="hljs-string">&quot;This is color %d\r\n&quot;</span>, color);<br>　cprintf(<span class="hljs-string">&quot;Press any key to continue\r\n&quot;</span>);<br>　getch();<span class="hljs-comment">/*输入字符看不见*/</span><br>　&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 33】<br>题目：学习 gotoxy()与 clrscr()函数　　　 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br>clrscr();<span class="hljs-comment">/*清屏函数*/</span><br>textbackground(<span class="hljs-number">2</span>);<br>gotoxy(<span class="hljs-number">1</span>, <span class="hljs-number">5</span>);<span class="hljs-comment">/*定位函数*/</span><br>cprintf(<span class="hljs-string">&quot;Output at row 5 column 1\n&quot;</span>);<br>textbackground(<span class="hljs-number">3</span>);<br>gotoxy(<span class="hljs-number">20</span>, <span class="hljs-number">10</span>);<br>cprintf(<span class="hljs-string">&quot;Output at row 10 column 20\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 34】<br>题目：练习函数调用</p>
<ol>
<li>程序分析： 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">hello_world</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br>printf(<span class="hljs-string">&quot;Hello, world!\n&quot;</span>);<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">three_hellos</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br><span class="hljs-type">int</span> counter;<br><span class="hljs-keyword">for</span> (counter = <span class="hljs-number">1</span>; counter &lt;= <span class="hljs-number">3</span>; counter++)<br>hello_world();<span class="hljs-comment">/*调用此函数*/</span><br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br>three_hellos();<span class="hljs-comment">/*调用此函数*/</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 35】<br>题目：文本颜色设置 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br><span class="hljs-type">int</span> color;<br><span class="hljs-keyword">for</span> (color = <span class="hljs-number">1</span>; color &lt; <span class="hljs-number">16</span>; color++)<br>　&#123;<br>　textcolor(color);<span class="hljs-comment">/*设置文本颜色*/</span><br>　cprintf(<span class="hljs-string">&quot;This is color %d\r\n&quot;</span>, color);<br>　&#125;<br>textcolor(<span class="hljs-number">128</span> + <span class="hljs-number">15</span>);<br>cprintf(<span class="hljs-string">&quot;This is blinking\r\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 36】<br>题目：求 100 之内的素数　　　 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">#include<br>#include <span class="hljs-string">&quot;math.h&quot;</span><br>#define N <span class="hljs-number">101</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j,line,a[N];<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>;ifor(i=<span class="hljs-number">2</span>;i　<span class="hljs-title function_">for</span><span class="hljs-params">(j=i+<span class="hljs-number">1</span>;j　&#123;</span><br><span class="hljs-params">　　<span class="hljs-keyword">if</span>(a[i]!=<span class="hljs-number">0</span>&amp;&amp;a[j]!=<span class="hljs-number">0</span>)</span><br>　　<span class="hljs-keyword">if</span>(a[j]%a[i]==<span class="hljs-number">0</span>)<br>　　a[j]=<span class="hljs-number">0</span>;&#125;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>,line=<span class="hljs-number">0</span>;i&#123;<br>　<span class="hljs-keyword">if</span>(a[i]!=<span class="hljs-number">0</span>)<br>　&#123;printf(<span class="hljs-string">&quot;%5d&quot;</span>,a[i]);<br>　line++;&#125;<br>　<span class="hljs-keyword">if</span>(line==<span class="hljs-number">10</span>)<br>　&#123;printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>line=<span class="hljs-number">0</span>;&#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 37】<br>题目：对 10 个数进行排序 1.程序分析：可以利用选择法，即从后 9 个比较过程中，选择一个最小的与第一个元素交换，<br>　　　　　　下次类推，即用第二个元素与后 8 个进行比较，并进行交换。 　　　　　　 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java">#define N <span class="hljs-number">10</span><br>main()<br>&#123;<span class="hljs-type">int</span> i,j,min,tem,a[N];<br><span class="hljs-comment">/*input data*/</span><br>printf(<span class="hljs-string">&quot;please input ten num:\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&#123;<br>printf(<span class="hljs-string">&quot;a[%d]=&quot;</span>,i);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;a[i]);&#125;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;iprintf(<span class="hljs-string">&quot;%5d&quot;</span>,a[i]);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-comment">/*sort ten num*/</span><br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&#123;min=i;<br><span class="hljs-keyword">for</span>(j=i+<span class="hljs-number">1</span>;jif(a[min]&gt;a[j]) min=j;<br>tem=a[i];<br>a[i]=a[min];<br>a[min]=tem;<br>&#125;<br><span class="hljs-comment">/*output data*/</span><br>printf(<span class="hljs-string">&quot;After sorted \n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;iprintf(<span class="hljs-string">&quot;%5d&quot;</span>,a[i]);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 38】<br>题目：求一个 3*3 矩阵对角线元素之和 1.程序分析：利用双重 for 循环控制输入二维数组，再将 a[i][i]累加后输出。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">float</span> a[<span class="hljs-number">3</span>][<span class="hljs-number">3</span>],sum=<span class="hljs-number">0</span>;<br><span class="hljs-type">int</span> i,j;<br>printf(<span class="hljs-string">&quot;please input rectangle element:\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3</span>;i++)<br>　<span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;<span class="hljs-number">3</span>;j++)<br>　scanf(<span class="hljs-string">&quot;%f&quot;</span>,&amp;a[i][j]);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3</span>;i++)<br>　sum=sum+a[i][i];<br>printf(<span class="hljs-string">&quot;duijiaoxian he is %6.2f&quot;</span>,sum);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 39】<br>题目：有一个已经排好序的数组。现输入一个数，要求按原来的规律将它插入数组中。</p>
<ol>
<li>程序分析：首先判断此数是否大于最后一个数，然后再考虑插入中间的数的情况，插入后<br>　　　　　此元素之后的数，依次后移一个位置。 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> a[<span class="hljs-number">11</span>]=&#123;<span class="hljs-number">1</span>,<span class="hljs-number">4</span>,<span class="hljs-number">6</span>,<span class="hljs-number">9</span>,<span class="hljs-number">13</span>,<span class="hljs-number">16</span>,<span class="hljs-number">19</span>,<span class="hljs-number">28</span>,<span class="hljs-number">40</span>,<span class="hljs-number">100</span>&#125;;<br><span class="hljs-type">int</span> temp1,temp2,number,end,i,j;<br>printf(<span class="hljs-string">&quot;original array is:\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">10</span>;i++)<br>　printf(<span class="hljs-string">&quot;%5d&quot;</span>,a[i]);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>printf(<span class="hljs-string">&quot;insert a new number:&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;number);<br>end=a[<span class="hljs-number">9</span>];<br><span class="hljs-keyword">if</span>(number&gt;end)<br>　a[<span class="hljs-number">10</span>]=number;<br><span class="hljs-keyword">else</span><br>　&#123;<span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">10</span>;i++)<br>　　&#123; <span class="hljs-keyword">if</span>(a[i]&gt;number)<br>　　　&#123;temp1=a[i];<br>　　　　a[i]=number;<br>　　　<span class="hljs-keyword">for</span>(j=i+<span class="hljs-number">1</span>;j&lt;<span class="hljs-number">11</span>;j++)<br>　　　&#123;temp2=a[j];<br>　　　　a[j]=temp1;<br>　　　　temp1=temp2;<br>　　　&#125;<br>　　　<span class="hljs-keyword">break</span>;<br>　　　&#125;<br>　　&#125;<br>&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">11</span>;i++)<br>　printf(<span class="hljs-string">&quot;%6d&quot;</span>,a[i]);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 40】<br>题目：将一个数组逆序输出。 1.程序分析：用第一个与最后一个交换。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">#define N <span class="hljs-number">5</span><br>main()<br>&#123; <span class="hljs-type">int</span> a[N]=&#123;<span class="hljs-number">9</span>,<span class="hljs-number">6</span>,<span class="hljs-number">5</span>,<span class="hljs-number">4</span>,<span class="hljs-number">1</span>&#125;,i,temp;<br>　printf(<span class="hljs-string">&quot;\n original array:\n&quot;</span>);<br>　<span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i　<span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%4d&quot;</span>,a[i])</span>;<br>　<span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i　&#123;temp=a[i];<br>　　a[i]=a[N-i-<span class="hljs-number">1</span>];<br>　　a[N-i-<span class="hljs-number">1</span>]=temp;<br>　&#125;<br>printf(<span class="hljs-string">&quot;\n sorted array:\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i　<span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%4d&quot;</span>,a[i])</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 41】<br>题目：学习 static 定义静态变量的用法 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>varfunc()<br>&#123;<br><span class="hljs-type">int</span> <span class="hljs-keyword">var</span>=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">static</span> <span class="hljs-type">int</span> static_var=<span class="hljs-number">0</span>;<br>printf(<span class="hljs-string">&quot;\40:var equal %d \n&quot;</span>,<span class="hljs-keyword">var</span>);<br>printf(<span class="hljs-string">&quot;\40:static var equal %d \n&quot;</span>,static_var);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">var</span>++;<br>static_var++;<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123;<span class="hljs-type">int</span> i;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3</span>;i++)<br>varfunc();<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 42】<br>题目：学习使用 auto 定义变量的用法 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">int</span> i,num;<br>num=<span class="hljs-number">2</span>;<br><span class="hljs-keyword">for</span> (i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3</span>;i++)<br>&#123; printf(<span class="hljs-string">&quot;\40: The num equal %d \n&quot;</span>,num);<br>num++;<br>&#123;<br>auto <span class="hljs-type">int</span> num=<span class="hljs-number">1</span>;<br>printf(<span class="hljs-string">&quot;\40: The internal block num equal %d \n&quot;</span>,num);<br>num++;<br>&#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 43】<br>题目：学习使用 static 的另一用法。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,num;<br>num=<span class="hljs-number">2</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3</span>;i++)<br>&#123;<br>printf(<span class="hljs-string">&quot;\40: The num equal %d \n&quot;</span>,num);<br>num++;<br>&#123;<br><span class="hljs-keyword">static</span> <span class="hljs-type">int</span> num=<span class="hljs-number">1</span>;<br>printf(<span class="hljs-string">&quot;\40:The internal block num equal %d\n&quot;</span>,num);<br>num++;<br>&#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 44】<br>题目：学习使用 external 的用法。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br><span class="hljs-type">int</span> a,b,c;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">add</span><span class="hljs-params">()</span><br>&#123; <span class="hljs-type">int</span> a;<br>a=<span class="hljs-number">3</span>;<br>c=a+b;<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; a=b=<span class="hljs-number">4</span>;<br>add();<br>printf(<span class="hljs-string">&quot;The value of c is equal to %d\n&quot;</span>,c);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 45】<br>题目：学习使用 register 定义变量的方法。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123;<br>register <span class="hljs-type">int</span> i;<br><span class="hljs-type">int</span> tmp=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;=<span class="hljs-number">100</span>;i++)<br>tmp+=i;<br>printf(<span class="hljs-string">&quot;The sum is %d\n&quot;</span>,tmp);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 46】<br>题目：宏#define 命令练习(1) 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#define TRUE <span class="hljs-number">1</span><br>#define FALSE <span class="hljs-number">0</span><br>#define <span class="hljs-title function_">SQ</span><span class="hljs-params">(x)</span> (x)*(x)<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123;<br><span class="hljs-type">int</span> num;<br><span class="hljs-type">int</span> again=<span class="hljs-number">1</span>;<br>printf(<span class="hljs-string">&quot;\40: Program will stop if input value less than 50.\n&quot;</span>);<br><span class="hljs-keyword">while</span>(again)<br>&#123;<br>printf(<span class="hljs-string">&quot;\40:Please input number==&gt;&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;num);<br>printf(<span class="hljs-string">&quot;\40:The square for this number is %d \n&quot;</span>,SQ(num));<br><span class="hljs-keyword">if</span>(num&gt;=<span class="hljs-number">50</span>)<br>again=TRUE;<br><span class="hljs-keyword">else</span><br>again=FALSE;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 47】<br>题目：宏#define 命令练习(2) 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#define <span class="hljs-title function_">exchange</span><span class="hljs-params">(a,b)</span> &#123; \ <span class="hljs-comment">/*宏定义中允许包含两道衣裳命令的情形，此时必须在最右边加上&quot;\&quot;*/</span><br><span class="hljs-type">int</span> t;\<br>t=a;\<br>a=b;\<br>b=t;\<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br><span class="hljs-type">int</span> x=<span class="hljs-number">10</span>;<br><span class="hljs-type">int</span> y=<span class="hljs-number">20</span>;<br>printf(<span class="hljs-string">&quot;x=%d; y=%d\n&quot;</span>,x,y);<br>exchange(x,y);<br>printf(<span class="hljs-string">&quot;x=%d; y=%d\n&quot;</span>,x,y);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 48】<br>题目：宏#define 命令练习(3) 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">#define LAG &gt;<br>#define SMA &lt;<br>#define EQ ==<br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; <span class="hljs-type">int</span> i=<span class="hljs-number">10</span>;<br><span class="hljs-type">int</span> j=<span class="hljs-number">20</span>;<br><span class="hljs-keyword">if</span>(i LAG j)<br>printf(<span class="hljs-string">&quot;\40: %d larger than %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i EQ j)<br>printf(<span class="hljs-string">&quot;\40: %d equal to %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i SMA j)<br>printf(<span class="hljs-string">&quot;\40:%d smaller than %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: No such value.\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 49】<br>题目：#if #ifdef 和#ifndef 的综合应用。</p>
<ol>
<li>程序分析： 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#define MAX<br>#define <span class="hljs-title function_">MAXIMUM</span><span class="hljs-params">(x,y)</span> (x&gt;y)?x:y<br>#define <span class="hljs-title function_">MINIMUM</span><span class="hljs-params">(x,y)</span> (x&gt;y)?y:x<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; <span class="hljs-type">int</span> a=<span class="hljs-number">10</span>,b=<span class="hljs-number">20</span>;<br>#ifdef MAX<br><span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;\40: The larger one is %d\n&quot;</span>,MAXIMUM(a,b)</span>);<br>#<span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: The lower one is %d\n&quot;</span>,MINIMUM(a,b));<br>#endif<br>#ifndef MIN<br><span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;\40: The lower one is %d\n&quot;</span>,MINIMUM(a,b)</span>);<br>#<span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: The larger one is %d\n&quot;</span>,MAXIMUM(a,b));<br>#endif<br>#undef MAX<br>#ifdef MAX<br><span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;\40: The larger one is %d\n&quot;</span>,MAXIMUM(a,b)</span>);<br>#<span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: The lower one is %d\n&quot;</span>,MINIMUM(a,b));<br>#endif<br>#define MIN<br>#ifndef MIN<br><span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;\40: The lower one is %d\n&quot;</span>,MINIMUM(a,b)</span>);<br>#<span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: The larger one is %d\n&quot;</span>,MAXIMUM(a,b));<br>#endif<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 50】<br>题目：#include 的应用练习 1.程序分析： 2.程序源代码：<br>test.h 文件如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java">#define LAG &gt;<br>#define SMA &lt;<br>#define EQ ==<br>#include <span class="hljs-string">&quot;test.h&quot;</span> <span class="hljs-comment">/*一个新文件50.c，包含test.h*/</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; <span class="hljs-type">int</span> i=<span class="hljs-number">10</span>;<br><span class="hljs-type">int</span> j=<span class="hljs-number">20</span>;<br><span class="hljs-keyword">if</span>(i LAG j)<br>printf(<span class="hljs-string">&quot;\40: %d larger than %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i EQ j)<br>printf(<span class="hljs-string">&quot;\40: %d equal to %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i SMA j)<br>printf(<span class="hljs-string">&quot;\40:%d smaller than %d \n&quot;</span>,i,j);<br><span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\40: No such value.\n&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 51】<br>题目：学习使用按位与 &amp; 。 1.程序分析：0&amp;0&#x3D;0; 0&amp;1&#x3D;0; 1&amp;0&#x3D;0; 1&amp;1&#x3D;1 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> a,b;<br>a=<span class="hljs-number">077</span>;<br>b=a&amp;<span class="hljs-number">3</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>b&amp;=<span class="hljs-number">7</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 52】<br>题目：学习使用按位或 | 。 1.程序分析：0|0&#x3D;0; 0|1&#x3D;1; 1|0&#x3D;1; 1|1&#x3D;1 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> a,b;<br>a=<span class="hljs-number">077</span>;<br>b=a|<span class="hljs-number">3</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>b|=<span class="hljs-number">7</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 53】<br>题目：学习使用按位异或 ^ 。 1.程序分析：0^0&#x3D;0; 0^1&#x3D;1; 1^0&#x3D;1; 1^1&#x3D;0 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> a,b;<br>a=<span class="hljs-number">077</span>;<br>b=a^<span class="hljs-number">3</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>b^=<span class="hljs-number">7</span>;<br>printf(<span class="hljs-string">&quot;\40: The a &amp; b(decimal) is %d \n&quot;</span>,b);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 54】<br>题目：取一个整数 a 从右端开始的 4 ～ 7 位。<br>程序分析：可以这样考虑：<br>(1)先使 a 右移 4 位。<br>(2)设置一个低 4 位全为 1,其余全为 0 的数。可用<del>(</del>0&lt;&lt;4)<br>(3)将上面二者进行&amp;运算。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br>unsigned a,b,c,d;<br>scanf(<span class="hljs-string">&quot;%o&quot;</span>,&amp;a);<br>b=a&gt;&gt;<span class="hljs-number">4</span>;<br>c=~(~<span class="hljs-number">0</span>&lt;&lt;<span class="hljs-number">4</span>);<br>d=b&amp;c;<br>printf(<span class="hljs-string">&quot;%o\n%o\n&quot;</span>,a,d);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 55】<br>题目：学习使用按位取反<del>。 1.程序分析：</del>0&#x3D;1; ~1&#x3D;0; 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> a,b;<br>a=<span class="hljs-number">234</span>;<br>b=~a;<br>printf(<span class="hljs-string">&quot;\40: The a&#x27;s 1 complement(decimal) is %d \n&quot;</span>,b);<br>a=~a;<br>printf(<span class="hljs-string">&quot;\40: The a&#x27;s 1 complement(hexidecimal) is %x \n&quot;</span>,a);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 56】<br>题目：画图，学用 circle 画圆形。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*circle*/</span><br>#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">int</span> driver,mode,i;<br><span class="hljs-type">float</span> j=<span class="hljs-number">1</span>,k=<span class="hljs-number">1</span>;<br>driver=VGA;mode=VGAHI;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setbkcolor(YELLOW);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">25</span>;i++)<br>&#123;<br>setcolor(<span class="hljs-number">8</span>);<br>circle(<span class="hljs-number">310</span>,<span class="hljs-number">250</span>,k);<br>k=k+j;<br>j=j+<span class="hljs-number">0.3</span>;<br>&#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 57】<br>题目：画图，学用 line 画直线。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">int</span> driver,mode,i;<br><span class="hljs-type">float</span> x0,y0,y1,x1;<br><span class="hljs-type">float</span> j=<span class="hljs-number">12</span>,k;<br>driver=VGA;mode=VGAHI;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setbkcolor(GREEN);<br>x0=<span class="hljs-number">263</span>;y0=<span class="hljs-number">263</span>;y1=<span class="hljs-number">275</span>;x1=<span class="hljs-number">275</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">18</span>;i++)<br>&#123;<br>setcolor(<span class="hljs-number">5</span>);<br>line(x0,y0,x0,y1);<br>x0=x0-<span class="hljs-number">5</span>;<br>y0=y0-<span class="hljs-number">5</span>;<br>x1=x1+<span class="hljs-number">5</span>;<br>y1=y1+<span class="hljs-number">5</span>;<br>j=j+<span class="hljs-number">10</span>;<br>&#125;<br>x0=<span class="hljs-number">263</span>;y1=<span class="hljs-number">275</span>;y0=<span class="hljs-number">263</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">20</span>;i++)<br>&#123;<br>setcolor(<span class="hljs-number">5</span>);<br>line(x0,y0,x0,y1);<br>x0=x0+<span class="hljs-number">5</span>;<br>y0=y0+<span class="hljs-number">5</span>;<br>y1=y1-<span class="hljs-number">5</span>;<br>&#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 58】<br>题目：画图，学用 rectangle 画方形。 1.程序分析：利用 for 循环控制 100-999 个数，每个数分解出个位，十位，百位。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">int</span> x0,y0,y1,x1,driver,mode,i;<br>driver=VGA;mode=VGAHI;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setbkcolor(YELLOW);<br>x0=<span class="hljs-number">263</span>;y0=<span class="hljs-number">263</span>;y1=<span class="hljs-number">275</span>;x1=<span class="hljs-number">275</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">18</span>;i++)<br>&#123;<br>setcolor(<span class="hljs-number">1</span>);<br>rectangle(x0,y0,x1,y1);<br>x0=x0-<span class="hljs-number">5</span>;<br>y0=y0-<span class="hljs-number">5</span>;<br>x1=x1+<span class="hljs-number">5</span>;<br>y1=y1+<span class="hljs-number">5</span>;<br>&#125;<br>settextstyle(DEFAULT_FONT,HORIZ_DIR,<span class="hljs-number">2</span>);<br>outtextxy(<span class="hljs-number">150</span>,<span class="hljs-number">40</span>,<span class="hljs-string">&quot;How beautiful it is!&quot;</span>);<br>line(<span class="hljs-number">130</span>,<span class="hljs-number">60</span>,<span class="hljs-number">480</span>,<span class="hljs-number">60</span>);<br>setcolor(<span class="hljs-number">2</span>);<br>circle(<span class="hljs-number">269</span>,<span class="hljs-number">269</span>,<span class="hljs-number">137</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 59】<br>题目：画图，综合例子。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><code class="hljs java"># define PAI <span class="hljs-number">3.1415926</span><br># define B <span class="hljs-number">0.809</span><br># include <span class="hljs-string">&quot;graphics.h&quot;</span><br>#include <span class="hljs-string">&quot;math.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j,k,x0,y0,x,y,driver,mode;<br><span class="hljs-type">float</span> a;<br>driver=CGA;mode=CGAC0;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setcolor(<span class="hljs-number">3</span>);<br>setbkcolor(GREEN);<br>x0=<span class="hljs-number">150</span>;y0=<span class="hljs-number">100</span>;<br>circle(x0,y0,<span class="hljs-number">10</span>);<br>circle(x0,y0,<span class="hljs-number">20</span>);<br>circle(x0,y0,<span class="hljs-number">50</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">16</span>;i++)<br>&#123;<br>a=(<span class="hljs-number">2</span>*PAI/<span class="hljs-number">16</span>)*i;<br>x=ceil(x0+<span class="hljs-number">48</span>*cos(a));<br>y=ceil(y0+<span class="hljs-number">48</span>*sin(a)*B);<br>setcolor(<span class="hljs-number">2</span>); line(x0,y0,x,y);&#125;<br>setcolor(<span class="hljs-number">3</span>);circle(x0,y0,<span class="hljs-number">60</span>);<br><span class="hljs-comment">/* Make 0 time normal size letters */</span><br>settextstyle(DEFAULT_FONT,HORIZ_DIR,<span class="hljs-number">0</span>);<br>outtextxy(<span class="hljs-number">10</span>,<span class="hljs-number">170</span>,<span class="hljs-string">&quot;press a key&quot;</span>);<br>getch();<br>setfillstyle(HATCH_FILL,YELLOW);<br>floodfill(<span class="hljs-number">202</span>,<span class="hljs-number">100</span>,WHITE);<br>getch();<br><span class="hljs-keyword">for</span>(k=<span class="hljs-number">0</span>;k&lt;=<span class="hljs-number">500</span>;k++)<br>&#123;<br>setcolor(<span class="hljs-number">3</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">16</span>;i++)<br>&#123;<br>a=(<span class="hljs-number">2</span>*PAI/<span class="hljs-number">16</span>)*i+(<span class="hljs-number">2</span>*PAI/<span class="hljs-number">180</span>)*k;<br>x=ceil(x0+<span class="hljs-number">48</span>*cos(a));<br>y=ceil(y0+<span class="hljs-number">48</span>+sin(a)*B);<br>setcolor(<span class="hljs-number">2</span>); line(x0,y0,x,y);<br>&#125;<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">1</span>;j&lt;=<span class="hljs-number">50</span>;j++)<br>&#123;<br>a=(<span class="hljs-number">2</span>*PAI/<span class="hljs-number">16</span>)*i+(<span class="hljs-number">2</span>*PAI/<span class="hljs-number">180</span>)*k-<span class="hljs-number">1</span>;<br>x=ceil(x0+<span class="hljs-number">48</span>*cos(a));<br>y=ceil(y0+<span class="hljs-number">48</span>*sin(a)*B);<br>line(x0,y0,x,y);<br>&#125;<br>&#125;<br>restorecrtmode();<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 60】<br>题目：画图，综合例子。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>#define LEFT <span class="hljs-number">0</span><br>#define TOP <span class="hljs-number">0</span><br>#define RIGHT <span class="hljs-number">639</span><br>#define BOTTOM <span class="hljs-number">479</span><br>#define LINES <span class="hljs-number">400</span><br>#define MAXCOLOR <span class="hljs-number">15</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> driver,mode,error;<br><span class="hljs-type">int</span> x1,y1;<br><span class="hljs-type">int</span> x2,y2;<br><span class="hljs-type">int</span> dx1,dy1,dx2,dy2,i=<span class="hljs-number">1</span>;<br><span class="hljs-type">int</span> count=<span class="hljs-number">0</span>;<br><span class="hljs-type">int</span> color=<span class="hljs-number">0</span>;<br>driver=VGA;<br>mode=VGAHI;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>x1=x2=y1=y2=<span class="hljs-number">10</span>;<br>dx1=dy1=<span class="hljs-number">2</span>;<br>dx2=dy2=<span class="hljs-number">3</span>;<br><span class="hljs-keyword">while</span>(!kbhit())<br>&#123;<br>line(x1,y1,x2,y2);<br>x1+=dx1;y1+=dy1;<br>x2+=dx2;y2+dy2;<br><span class="hljs-keyword">if</span>(x1&lt;=LEFT||x1&gt;=RIGHT)<br>dx1=-dx1;<br><span class="hljs-keyword">if</span>(y1&lt;=TOP||y1&gt;=BOTTOM)<br>dy1=-dy1;<br><span class="hljs-keyword">if</span>(x2&lt;=LEFT||x2&gt;=RIGHT)<br>dx2=-dx2;<br><span class="hljs-keyword">if</span>(y2&lt;=TOP||y2&gt;=BOTTOM)<br>dy2=-dy2;<br><span class="hljs-keyword">if</span>(++count&gt;LINES)<br>&#123;<br>setcolor(color);<br>color=(color&gt;=MAXCOLOR)?<span class="hljs-number">0</span>:++color;<br>&#125;<br>&#125;<br>closegraph();<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 61】<br>题目：打印出杨辉三角形（要求打印出 10 行如下图） 1.程序分析：<br>1<br>1 1<br>1 2 1<br>1 3 3 1<br>1 4 6 4 1<br>1 5 10 10 5 1 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<span class="hljs-type">int</span> i,j;<br><span class="hljs-type">int</span> a[<span class="hljs-number">10</span>][<span class="hljs-number">10</span>];<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">10</span>;i++)<br>&#123;a[i][<span class="hljs-number">0</span>]=<span class="hljs-number">1</span>;<br>a[i][i]=<span class="hljs-number">1</span>;&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>;i&lt;<span class="hljs-number">10</span>;i++)<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">1</span>;j a[i][j]=a[i-<span class="hljs-number">1</span>][j-<span class="hljs-number">1</span>]+a[i-<span class="hljs-number">1</span>][j];<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">10</span>;i++)<br>&#123;<span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;=i;j++)<br>printf(<span class="hljs-string">&quot;]&quot;</span>,a[i][j]);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 62】<br>题目：学习 putpixel 画点。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,j,driver=VGA,mode=VGAHI;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setbkcolor(YELLOW);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">50</span>;i&lt;=<span class="hljs-number">230</span>;i+=<span class="hljs-number">20</span>)<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">50</span>;j&lt;=<span class="hljs-number">230</span>;j++)<br>putpixel(i,j,<span class="hljs-number">1</span>);<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">50</span>;j&lt;=<span class="hljs-number">230</span>;j+=<span class="hljs-number">20</span>)<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">50</span>;i&lt;=<span class="hljs-number">230</span>;i++)<br>putpixel(i,j,<span class="hljs-number">1</span>);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 63】<br>题目：画椭圆 ellipse 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>#include <span class="hljs-string">&quot;conio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> x=<span class="hljs-number">360</span>,y=<span class="hljs-number">160</span>,driver=VGA,mode=VGAHI;<br><span class="hljs-type">int</span> num=<span class="hljs-number">20</span>,i;<br><span class="hljs-type">int</span> top,bottom;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>top=y-<span class="hljs-number">30</span>;<br>bottom=y-<span class="hljs-number">30</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&#123;<br>ellipse(<span class="hljs-number">250</span>,<span class="hljs-number">250</span>,<span class="hljs-number">0</span>,<span class="hljs-number">360</span>,top,bottom);<br>top-=<span class="hljs-number">5</span>;<br>bottom+=<span class="hljs-number">5</span>;<br>&#125;<br>getch();<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 64】<br>题目：利用 ellipse and rectangle 画图。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>#include <span class="hljs-string">&quot;conio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> driver=VGA,mode=VGAHI;<br><span class="hljs-type">int</span> i,num=<span class="hljs-number">15</span>,top=<span class="hljs-number">50</span>;<br><span class="hljs-type">int</span> left=<span class="hljs-number">20</span>,right=<span class="hljs-number">50</span>;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&#123;<br>ellipse(<span class="hljs-number">250</span>,<span class="hljs-number">250</span>,<span class="hljs-number">0</span>,<span class="hljs-number">360</span>,right,left);<br>ellipse(<span class="hljs-number">250</span>,<span class="hljs-number">250</span>,<span class="hljs-number">0</span>,<span class="hljs-number">360</span>,<span class="hljs-number">20</span>,top);<br>rectangle(<span class="hljs-number">20</span>-<span class="hljs-number">2</span>*i,<span class="hljs-number">20</span>-<span class="hljs-number">2</span>*i,<span class="hljs-number">10</span>*(i+<span class="hljs-number">2</span>),<span class="hljs-number">10</span>*(i+<span class="hljs-number">2</span>));<br>right+=<span class="hljs-number">5</span>;<br>left+=<span class="hljs-number">5</span>;<br>top+=<span class="hljs-number">10</span>;<br>&#125;<br>getch();<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 65】<br>题目：一个最优美的图案。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;graphics.h&quot;</span><br>#include <span class="hljs-string">&quot;math.h&quot;</span><br>#include <span class="hljs-string">&quot;dos.h&quot;</span><br>#include <span class="hljs-string">&quot;conio.h&quot;</span><br>#include <span class="hljs-string">&quot;stdlib.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;stdarg.h&quot;</span><br>#define MAXPTS <span class="hljs-number">15</span><br>#define PI <span class="hljs-number">3.1415926</span><br>struct PTS &#123;<br><span class="hljs-type">int</span> x,y;<br>&#125;;<br><span class="hljs-type">double</span> AspectRatio=<span class="hljs-number">0.85</span>;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">LineToDemo</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123;<br>struct viewporttype vp;<br>struct PTS points[MAXPTS];<br><span class="hljs-type">int</span> i, j, h, w, xcenter, ycenter;<br><span class="hljs-type">int</span> radius, angle, step;<br><span class="hljs-type">double</span> rads;<br>printf(<span class="hljs-string">&quot; MoveTo / LineTo Demonstration&quot;</span> );<br>getviewsettings( &amp;vp );<br>h = vp.bottom - vp.top;<br>w = vp.right - vp.left;<br>xcenter = w / <span class="hljs-number">2</span>; <span class="hljs-comment">/* Determine the center of circle */</span><br>ycenter = h / <span class="hljs-number">2</span>;<br>radius = (h - <span class="hljs-number">30</span>) / (AspectRatio * <span class="hljs-number">2</span>);<br>step = <span class="hljs-number">360</span> / MAXPTS; <span class="hljs-comment">/* Determine # of increments */</span><br>angle = <span class="hljs-number">0</span>; <span class="hljs-comment">/* Begin at zero degrees */</span><br><span class="hljs-keyword">for</span>( i=<span class="hljs-number">0</span> ; irads = (<span class="hljs-type">double</span>)angle * PI / <span class="hljs-number">180.0</span>; <span class="hljs-comment">/* Convert angle to radians */</span><br>points[i].x = xcenter + (<span class="hljs-type">int</span>)( cos(rads) * radius );<br>points[i].y = ycenter - (<span class="hljs-type">int</span>)( sin(rads) * radius * AspectRatio );<br>angle += step; <span class="hljs-comment">/* Move to next increment */</span><br>&#125;<br>circle( xcenter, ycenter, radius ); <span class="hljs-comment">/* Draw bounding circle */</span><br><span class="hljs-keyword">for</span>( i=<span class="hljs-number">0</span> ; ifor( j=i ; jmoveto(points[i].x, points[i].y); <span class="hljs-comment">/* Move to beginning of cord */</span><br>lineto(points[j].x, points[j].y); <span class="hljs-comment">/* Draw the cord */</span><br>&#125; &#125; &#125;<br>main()<br>&#123;<span class="hljs-type">int</span> driver,mode;<br>driver=CGA;mode=CGAC0;<br>initgraph(&amp;driver,&amp;mode,<span class="hljs-string">&quot;&quot;</span>);<br>setcolor(<span class="hljs-number">3</span>);<br>setbkcolor(GREEN);<br>LineToDemo();&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 66】<br>题目：输入 3 个数 a,b,c，按大小顺序输出。 1.程序分析：利用指针方法。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*pointer*/</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> n1,n2,n3;<br><span class="hljs-type">int</span> *pointer1,*pointer2,*pointer3;<br>printf(<span class="hljs-string">&quot;please input 3 number:n1,n2,n3:&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d,%d,%d&quot;</span>,&amp;n1,&amp;n2,&amp;n3);<br>pointer1=&amp;n1;<br>pointer2=&amp;n2;<br>pointer3=&amp;n3;<br><span class="hljs-keyword">if</span>(n1&gt;n2) swap(pointer1,pointer2);<br><span class="hljs-keyword">if</span>(n1&gt;n3) swap(pointer1,pointer3);<br><span class="hljs-keyword">if</span>(n2&gt;n3) swap(pointer2,pointer3);<br>printf(<span class="hljs-string">&quot;the sorted numbers are:%d,%d,%d\n&quot;</span>,n1,n2,n3);<br>&#125;<br>swap(p1,p2)<br><span class="hljs-type">int</span> *p1,*p2;<br>&#123;<span class="hljs-type">int</span> p;<br>p=*p1;*p1=*p2;*p2=p;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 67】<br>题目：输入数组，最大的与第一个元素交换，最小的与最后一个元素交换，输出数组。 1.程序分析：谭浩强的书中答案有问题。 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> number[<span class="hljs-number">10</span>];<br>input(number);<br>max_min(number);<br>output(number);<br>&#125;<br>input(number)<br><span class="hljs-type">int</span> number[<span class="hljs-number">10</span>];<br>&#123;<span class="hljs-type">int</span> i;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">9</span>;i++)<br>scanf(<span class="hljs-string">&quot;%d,&quot;</span>,&amp;number[i]);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;number[<span class="hljs-number">9</span>]);<br>&#125;<br>max_min(array)<br><span class="hljs-type">int</span> array[<span class="hljs-number">10</span>];<br>&#123;<span class="hljs-type">int</span> *max,*min,k,l;<br><span class="hljs-type">int</span> *p,*arr_end;<br>arr_end=array+<span class="hljs-number">10</span>;<br>max=min=array;<br><span class="hljs-keyword">for</span>(p=array+<span class="hljs-number">1</span>;p <span class="hljs-title function_">if</span><span class="hljs-params">(*p&gt;*max)</span> max=p;<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(*p&lt;*min) min=p;<br>k=*max;<br>l=*min;<br>*p=array[<span class="hljs-number">0</span>];array[<span class="hljs-number">0</span>]=l;l=*p;<br>*p=array[<span class="hljs-number">9</span>];array[<span class="hljs-number">9</span>]=k;k=*p;<br><span class="hljs-keyword">return</span>;<br>&#125;<br>output(array)<br><span class="hljs-type">int</span> array[<span class="hljs-number">10</span>];<br>&#123; <span class="hljs-type">int</span> *p;<br><span class="hljs-keyword">for</span>(p=array;p <span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%d,&quot;</span>,*p)</span>;<br>printf(<span class="hljs-string">&quot;%d\n&quot;</span>,array[<span class="hljs-number">9</span>]);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 68】<br>题目：有 n 个整数，使其前面各数顺序向后移 m 个位置，最后 m 个数变成最前面的 m 个数 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> number[<span class="hljs-number">20</span>],n,m,i;<br>printf(<span class="hljs-string">&quot;the total numbers is:&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;n);<br>printf(<span class="hljs-string">&quot;back m:&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;m);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i <span class="hljs-title function_">scanf</span><span class="hljs-params">(<span class="hljs-string">&quot;%d,&quot;</span>,&amp;number[i])</span>;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;number[n-<span class="hljs-number">1</span>]);<br>move(number,n,m);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i <span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%d,&quot;</span>,number[i])</span>;<br>printf(<span class="hljs-string">&quot;%d&quot;</span>,number[n-<span class="hljs-number">1</span>]);<br>&#125;<br>move(array,n,m)<br><span class="hljs-type">int</span> n,m,array[<span class="hljs-number">20</span>];<br>&#123;<br><span class="hljs-type">int</span> *p,array_end;<br>array_end=*(array+n-<span class="hljs-number">1</span>);<br><span class="hljs-keyword">for</span>(p=array+n-<span class="hljs-number">1</span>;p&gt;array;p--)<br>*p=*(p-<span class="hljs-number">1</span>);<br>*array=array_end;<br>m--;<br><span class="hljs-keyword">if</span>(m&gt;<span class="hljs-number">0</span>) move(array,n,m);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 69】<br>题目：有 n 个人围成一圈，顺序排号。从第一个人开始报数（从 1 到 3 报数），凡报到 3 的人退出<br>圈子，问最后留下的是原来第几号的那位。</p>
<ol>
<li>程序分析： 2.程序源代码：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java">#define nmax <span class="hljs-number">50</span><br>main()<br>&#123;<br><span class="hljs-type">int</span> i,k,m,n,num[nmax],*p;<br>printf(<span class="hljs-string">&quot;please input the total of numbers:&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;n);<br>p=num;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i *(p+i)=i+<span class="hljs-number">1</span>;<br>i=<span class="hljs-number">0</span>;<br>k=<span class="hljs-number">0</span>;<br>m=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">while</span>(m &#123;<br><span class="hljs-keyword">if</span>(*(p+i)!=<span class="hljs-number">0</span>) k++;<br><span class="hljs-keyword">if</span>(k==<span class="hljs-number">3</span>)<br>&#123; *(p+i)=<span class="hljs-number">0</span>;<br>k=<span class="hljs-number">0</span>;<br>m++;<br>&#125;<br>i++;<br><span class="hljs-keyword">if</span>(i==n) i=<span class="hljs-number">0</span>;<br>&#125;<br><span class="hljs-keyword">while</span>(*p==<span class="hljs-number">0</span>) p++;<br>printf(<span class="hljs-string">&quot;%d is left\n&quot;</span>,*p);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 70】<br>题目：写一个函数，求一个字符串的长度，在 main 函数中输入字符串，并输出其长度。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> len;<br><span class="hljs-type">char</span> *str[<span class="hljs-number">20</span>];<br>printf(<span class="hljs-string">&quot;please input a string:\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,str);<br>len=length(str);<br>printf(<span class="hljs-string">&quot;the string has %d characters.&quot;</span>,len);<br>&#125;<br>length(p)<br><span class="hljs-type">char</span> *p;<br>&#123;<br><span class="hljs-type">int</span> n;<br>n=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">while</span>(*p!=<span class="hljs-string">&#x27;\0&#x27;</span>)<br>&#123;<br>n++;<br>p++;<br>&#125;<br><span class="hljs-keyword">return</span> n;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 71】<br>题目：编写 input()和 output()函数输入，输出 5 个学生的数据记录。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><code class="hljs java">#define N <span class="hljs-number">5</span><br>struct student<br>&#123; <span class="hljs-type">char</span> num[<span class="hljs-number">6</span>];<br><span class="hljs-type">char</span> name[<span class="hljs-number">8</span>];<br><span class="hljs-type">int</span> score[<span class="hljs-number">4</span>];<br>&#125; stu[N];<br>input(stu)<br>struct student stu[];<br>&#123; <span class="hljs-type">int</span> i,j;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i &#123; printf(<span class="hljs-string">&quot;\n please input %d of %d\n&quot;</span>,i+<span class="hljs-number">1</span>,N);<br>printf(<span class="hljs-string">&quot;num: &quot;</span>);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,stu[i].num);<br>printf(<span class="hljs-string">&quot;name: &quot;</span>);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,stu[i].name);<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;<span class="hljs-number">3</span>;j++)<br>&#123; printf(<span class="hljs-string">&quot;score %d.&quot;</span>,j+<span class="hljs-number">1</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;stu[i].score[j]);<br>&#125;<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>&#125;<br>print(stu)<br>struct student stu[];<br>&#123; <span class="hljs-type">int</span> i,j;<br>printf(<span class="hljs-string">&quot;\nNo. Name Sco1 Sco2 Sco3\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&#123; printf(<span class="hljs-string">&quot;%-6s%-10s&quot;</span>,stu[i].num,stu[i].name);<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;<span class="hljs-number">3</span>;j++)<br>printf(<span class="hljs-string">&quot;%-8d&quot;</span>,stu[i].score[j]);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>&#125;<br>&#125;<br>main()<br>&#123;<br>input();<br>print();<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 72】<br>题目：创建一个链表。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*creat a list*/</span><br>#include <span class="hljs-string">&quot;stdlib.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>struct list<br>&#123; <span class="hljs-type">int</span> data;<br>struct list *next;<br>&#125;;<br>typedef struct list node;<br>typedef node *link;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; link ptr,head;<br><span class="hljs-type">int</span> num,i;<br>ptr=(link)malloc(sizeof(node));<br>ptr=head;<br>printf(<span class="hljs-string">&quot;please input 5 numbers==&gt;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">4</span>;i++)<br>&#123;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;num);<br>ptr-&gt;data=num;<br>ptr-&gt;next=(link)malloc(sizeof(node));<br><span class="hljs-keyword">if</span>(i==<span class="hljs-number">4</span>) ptr-&gt;next=NULL;<br><span class="hljs-keyword">else</span> ptr=ptr-&gt;next;<br>&#125;<br>ptr=head;<br><span class="hljs-keyword">while</span>(ptr!=NULL)<br>&#123; printf(<span class="hljs-string">&quot;The value is ==&gt;%d\n&quot;</span>,ptr-&gt;data);<br>ptr=ptr-&gt;next;<br>&#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 73】<br>题目：反向输出一个链表。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*reverse output a list*/</span><br>#include <span class="hljs-string">&quot;stdlib.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>struct list<br>&#123; <span class="hljs-type">int</span> data;<br>struct list *next;<br>&#125;;<br>typedef struct list node;<br>typedef node *link;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; link ptr,head,tail;<br><span class="hljs-type">int</span> num,i;<br>tail=(link)malloc(sizeof(node));<br>tail-&gt;next=NULL;<br>ptr=tail;<br>printf(<span class="hljs-string">&quot;\nplease input 5 data==&gt;\n&quot;</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">4</span>;i++)<br>&#123;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;num);<br>ptr-&gt;data=num;<br>head=(link)malloc(sizeof(node));<br>head-&gt;next=ptr;<br>ptr=head;<br>&#125;<br>ptr=ptr-&gt;next;<br><span class="hljs-keyword">while</span>(ptr!=NULL)<br>&#123; printf(<span class="hljs-string">&quot;The value is ==&gt;%d\n&quot;</span>,ptr-&gt;data);<br>ptr=ptr-&gt;next;<br>&#125;&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 74】<br>题目：连接两个链表。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdlib.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>struct list<br>&#123; <span class="hljs-type">int</span> data;<br>struct list *next;<br>&#125;;<br>typedef struct list node;<br>typedef node *link;<br>link <span class="hljs-title function_">delete_node</span><span class="hljs-params">(link pointer,link tmp)</span><br>&#123;<span class="hljs-keyword">if</span> (tmp==NULL) <span class="hljs-comment">/*delete first node*/</span><br><span class="hljs-keyword">return</span> pointer-&gt;next;<br><span class="hljs-keyword">else</span><br>&#123; <span class="hljs-keyword">if</span>(tmp-&gt;next-&gt;next==NULL)<span class="hljs-comment">/*delete last node*/</span><br>tmp-&gt;next=NULL;<br><span class="hljs-keyword">else</span> <span class="hljs-comment">/*delete the other node*/</span><br>tmp-&gt;next=tmp-&gt;next-&gt;next;<br><span class="hljs-keyword">return</span> pointer;<br>&#125;<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">selection_sort</span><span class="hljs-params">(link pointer,<span class="hljs-type">int</span> num)</span><br>&#123; link tmp,btmp;<br><span class="hljs-type">int</span> i,min;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i &#123;<br>tmp=pointer;<br>min=tmp-&gt;data;<br>btmp=NULL;<br><span class="hljs-keyword">while</span>(tmp-&gt;next)<br>&#123; <span class="hljs-keyword">if</span>(min&gt;tmp-&gt;next-&gt;data)<br>&#123;min=tmp-&gt;next-&gt;data;<br>btmp=tmp;<br>&#125;<br>tmp=tmp-&gt;next;<br>&#125;<br>printf(<span class="hljs-string">&quot;\40: %d\n&quot;</span>,min);<br>pointer=delete_node(pointer,btmp);<br>&#125;<br>&#125;<br>link <span class="hljs-title function_">create_list</span><span class="hljs-params">(<span class="hljs-type">int</span> array[],<span class="hljs-type">int</span> num)</span><br>&#123; link tmp1,tmp2,pointer;<br><span class="hljs-type">int</span> i;<br>pointer=(link)malloc(sizeof(node));<br>pointer-&gt;data=array[<span class="hljs-number">0</span>];<br>tmp1=pointer;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&#123; tmp2=(link)malloc(sizeof(node));<br>tmp2-&gt;next=NULL;<br>tmp2-&gt;data=array[i];<br>tmp1-&gt;next=tmp2;<br>tmp1=tmp1-&gt;next;<br>&#125;<br><span class="hljs-keyword">return</span> pointer;<br>&#125;<br>link <span class="hljs-title function_">concatenate</span><span class="hljs-params">(link pointer1,link pointer2)</span><br>&#123; link tmp;<br>tmp=pointer1;<br><span class="hljs-keyword">while</span>(tmp-&gt;next)<br>tmp=tmp-&gt;next;<br>tmp-&gt;next=pointer2;<br><span class="hljs-keyword">return</span> pointer1;<br>&#125;<br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span><br>&#123; <span class="hljs-type">int</span> arr1[]=&#123;<span class="hljs-number">3</span>,<span class="hljs-number">12</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">11</span>&#125;;<br>link ptr;<br>ptr=create_list(arr1,<span class="hljs-number">5</span>);<br>selection_sort(ptr,<span class="hljs-number">5</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 75】<br>题目：放松一下，算一道简单的题目。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">int</span> i,n;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;<span class="hljs-number">5</span>;i++)<br>&#123; n=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">if</span>(i!=<span class="hljs-number">1</span>)<br>n=n+<span class="hljs-number">1</span>;<br><span class="hljs-keyword">if</span>(i==<span class="hljs-number">3</span>)<br>n=n+<span class="hljs-number">1</span>;<br><span class="hljs-keyword">if</span>(i==<span class="hljs-number">4</span>)<br>n=n+<span class="hljs-number">1</span>;<br><span class="hljs-keyword">if</span>(i!=<span class="hljs-number">4</span>)<br>n=n+<span class="hljs-number">1</span>;<br><span class="hljs-keyword">if</span>(n==<span class="hljs-number">3</span>)<br>printf(<span class="hljs-string">&quot;zhu hao shi de shi:%c&quot;</span>,<span class="hljs-number">64</span>+i);<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 76】<br>题目：编写一个函数，输入 n 为偶数时，调用函数求 1&#x2F;2+1&#x2F;4+…+1&#x2F;n,当输入 n 为奇数时，调用函数<br>1&#x2F;1+1&#x2F;3+…+1&#x2F;n(利用指针函数) 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<br><span class="hljs-type">float</span> <span class="hljs-title function_">peven</span><span class="hljs-params">()</span>,podd(),dcall();<br><span class="hljs-type">float</span> sum;<br><span class="hljs-type">int</span> n;<br><span class="hljs-keyword">while</span> (<span class="hljs-number">1</span>)<br>&#123;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;n);<br><span class="hljs-keyword">if</span>(n&gt;<span class="hljs-number">1</span>)<br><span class="hljs-keyword">break</span>;<br>&#125;<br><span class="hljs-keyword">if</span>(n%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>)<br>&#123;<br>printf(<span class="hljs-string">&quot;Even=&quot;</span>);<br>sum=dcall(peven,n);<br>&#125;<br><span class="hljs-keyword">else</span><br>&#123;<br>printf(<span class="hljs-string">&quot;Odd=&quot;</span>);<br>sum=dcall(podd,n);<br>&#125;<br>printf(<span class="hljs-string">&quot;%f&quot;</span>,sum);<br>&#125;<br><span class="hljs-type">float</span> <span class="hljs-title function_">peven</span><span class="hljs-params">(<span class="hljs-type">int</span> n)</span><br>&#123;<br><span class="hljs-type">float</span> s;<br><span class="hljs-type">int</span> i;<br>s=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">2</span>;i&lt;=n;i+=<span class="hljs-number">2</span>)<br>s+=<span class="hljs-number">1</span>/(<span class="hljs-type">float</span>)i;<br><span class="hljs-keyword">return</span>(s);<br>&#125;<br><span class="hljs-type">float</span> <span class="hljs-title function_">podd</span><span class="hljs-params">(n)</span><br><span class="hljs-type">int</span> n;<br>&#123;<br><span class="hljs-type">float</span> s;<br><span class="hljs-type">int</span> i;<br>s=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;=n;i+=<span class="hljs-number">2</span>)<br>s+=<span class="hljs-number">1</span>/(<span class="hljs-type">float</span>)i;<br><span class="hljs-keyword">return</span>(s);<br>&#125;<br><span class="hljs-type">float</span> <span class="hljs-title function_">dcall</span><span class="hljs-params">(fp,n)</span><br><span class="hljs-type">float</span> (*fp)();<br><span class="hljs-type">int</span> n;<br>&#123;<br><span class="hljs-type">float</span> s;<br>s=(*fp)(n);<br><span class="hljs-keyword">return</span>(s);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 77】<br>题目：填空练习（指向指针的指针） 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123; <span class="hljs-type">char</span> *s[]=&#123;<span class="hljs-string">&quot;man&quot;</span>,<span class="hljs-string">&quot;woman&quot;</span>,<span class="hljs-string">&quot;girl&quot;</span>,<span class="hljs-string">&quot;boy&quot;</span>,<span class="hljs-string">&quot;sister&quot;</span>&#125;;<br><span class="hljs-type">char</span> **q;<br><span class="hljs-type">int</span> k;<br><span class="hljs-keyword">for</span>(k=<span class="hljs-number">0</span>;k&lt;<span class="hljs-number">5</span>;k++)<br>&#123; ;<span class="hljs-comment">/*这里填写什么语句*/</span><br>printf(<span class="hljs-string">&quot;%s\n&quot;</span>,*q);<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 78】<br>题目：找到年龄最大的人，并输出。请找出程序中有什么问题。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">#define N <span class="hljs-number">4</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br><span class="hljs-keyword">static</span> struct man<br>&#123; <span class="hljs-type">char</span> name[<span class="hljs-number">20</span>];<br><span class="hljs-type">int</span> age;<br>&#125; person[N]=&#123;<span class="hljs-string">&quot;li&quot;</span>,<span class="hljs-number">18</span>,<span class="hljs-string">&quot;wang&quot;</span>,<span class="hljs-number">19</span>,<span class="hljs-string">&quot;zhang&quot;</span>,<span class="hljs-number">20</span>,<span class="hljs-string">&quot;sun&quot;</span>,<span class="hljs-number">22</span>&#125;;<br>main()<br>&#123;struct man *q,*p;<br><span class="hljs-type">int</span> i,m=<span class="hljs-number">0</span>;<br>p=person;<br><span class="hljs-keyword">for</span> (i=<span class="hljs-number">0</span>;i&#123;<span class="hljs-keyword">if</span>(mage)<br>q=p++;<br>m=q-&gt;age;&#125;<br>printf(<span class="hljs-string">&quot;%s,%d&quot;</span>,(*q).name,(*q).age);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 79】<br>题目：字符串排序。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">char</span> *str1[<span class="hljs-number">20</span>],*str2[<span class="hljs-number">20</span>],*str3[<span class="hljs-number">20</span>];<br><span class="hljs-type">char</span> <span class="hljs-title function_">swap</span><span class="hljs-params">()</span>;<br>printf(<span class="hljs-string">&quot;please input three strings\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,str1);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,str2);<br>scanf(<span class="hljs-string">&quot;%s&quot;</span>,str3);<br><span class="hljs-keyword">if</span>(strcmp(str1,str2)&gt;<span class="hljs-number">0</span>) swap(str1,str2);<br><span class="hljs-keyword">if</span>(strcmp(str1,str3)&gt;<span class="hljs-number">0</span>) swap(str1,str3);<br><span class="hljs-keyword">if</span>(strcmp(str2,str3)&gt;<span class="hljs-number">0</span>) swap(str2,str3);<br>printf(<span class="hljs-string">&quot;after being sorted\n&quot;</span>);<br>printf(<span class="hljs-string">&quot;%s\n%s\n%s\n&quot;</span>,str1,str2,str3);<br>&#125;<br><span class="hljs-type">char</span> <span class="hljs-title function_">swap</span><span class="hljs-params">(p1,p2)</span><br><span class="hljs-type">char</span> *p1,*p2;<br>&#123;<br><span class="hljs-type">char</span> *p[<span class="hljs-number">20</span>];<br>strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 80】<br>题目：海滩上有一堆桃子，五只猴子来分。第一只猴子把这堆桃子凭据分为五份，多了一个，这只<br>猴子把多的一个扔入海中，拿走了一份。第二只猴子把剩下的桃子又平均分成五份，又多了<br>一个，它同样把多的一个扔入海中，拿走了一份，第三、第四、第五只猴子都是这样做的，<br>问海滩上原来最少有多少个桃子？ 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<span class="hljs-type">int</span> i,m,j,k,count;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">4</span>;i&lt;<span class="hljs-number">10000</span>;i+=<span class="hljs-number">4</span>)<br>&#123; count=<span class="hljs-number">0</span>;<br>m=i;<br><span class="hljs-keyword">for</span>(k=<span class="hljs-number">0</span>;k&lt;<span class="hljs-number">5</span>;k++)<br>&#123;<br>j=i/<span class="hljs-number">4</span>*<span class="hljs-number">5</span>+<span class="hljs-number">1</span>;<br>i=j;<br><span class="hljs-keyword">if</span>(j%<span class="hljs-number">4</span>==<span class="hljs-number">0</span>)<br>count++;<br><span class="hljs-keyword">else</span><br><span class="hljs-keyword">break</span>;<br>&#125;<br>i=m;<br><span class="hljs-keyword">if</span>(count==<span class="hljs-number">4</span>)<br>&#123;printf(<span class="hljs-string">&quot;%d\n&quot;</span>,count);<br><span class="hljs-keyword">break</span>;&#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 81】<br>题目：809*??&#x3D;800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数，9*??的结果为 3 位数。求??代表的两位数，及 809*??后的结果。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java">output(<span class="hljs-type">long</span> b,<span class="hljs-type">long</span> i)<br>&#123; printf(<span class="hljs-string">&quot;\n%ld/%ld=809*%ld+%ld&quot;</span>,b,i,i,b%i);<br>&#125;<br>main()<br>&#123;<span class="hljs-type">long</span> <span class="hljs-type">int</span> a,b,i;<br>a=<span class="hljs-number">809</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">10</span>;i&lt;<span class="hljs-number">100</span>;i++)<br>&#123;b=i*a+<span class="hljs-number">1</span>;<br><span class="hljs-keyword">if</span>(b&gt;=<span class="hljs-number">1000</span>&amp;&amp;b&lt;=<span class="hljs-number">10000</span>&amp;&amp;<span class="hljs-number">8</span>*i&lt;<span class="hljs-number">100</span>&amp;&amp;<span class="hljs-number">9</span>*i&gt;=<span class="hljs-number">100</span>)<br>output(b,i); &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 82】<br>题目：八进制转换为十进制 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123; <span class="hljs-type">char</span> *p,s[<span class="hljs-number">6</span>];<span class="hljs-type">int</span> n;<br>p=s;<br>gets(p);<br>n=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">while</span>(*(p)!=<span class="hljs-string">&#x27;\0&#x27;</span>)<br>&#123;n=n*<span class="hljs-number">8</span>+*p-<span class="hljs-string">&#x27;0&#x27;</span>;<br>p++;&#125;<br>printf(<span class="hljs-string">&quot;%d&quot;</span>,n);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 83】<br>题目：求 0—7 所能组成的奇数个数。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<br><span class="hljs-type">long</span> sum=<span class="hljs-number">4</span>,s=<span class="hljs-number">4</span>;<br><span class="hljs-type">int</span> j;<br><span class="hljs-keyword">for</span>(j=<span class="hljs-number">2</span>;j&lt;=<span class="hljs-number">8</span>;j++)<span class="hljs-comment">/*j is place of number*/</span><br>&#123; printf(<span class="hljs-string">&quot;\n%ld&quot;</span>,sum);<br><span class="hljs-keyword">if</span>(j&lt;=<span class="hljs-number">2</span>)<br>s*=<span class="hljs-number">7</span>;<br><span class="hljs-keyword">else</span><br>s*=<span class="hljs-number">8</span>;<br>sum+=s;&#125;<br>printf(<span class="hljs-string">&quot;\nsum=%ld&quot;</span>,sum);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 84】<br>题目：一个偶数总能表示为两个素数之和。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;math.h&quot;</span><br>main()<br>&#123; <span class="hljs-type">int</span> a,b,c,d;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;a);<br><span class="hljs-keyword">for</span>(b=<span class="hljs-number">3</span>;b&lt;=a/<span class="hljs-number">2</span>;b+=<span class="hljs-number">2</span>)<br>&#123; <span class="hljs-keyword">for</span>(c=<span class="hljs-number">2</span>;c&lt;=sqrt(b);c++)<br><span class="hljs-keyword">if</span>(b%c==<span class="hljs-number">0</span>) <span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">if</span>(c&gt;sqrt(b))<br>d=a-b;<br><span class="hljs-keyword">else</span><br><span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">for</span>(c=<span class="hljs-number">2</span>;c&lt;=sqrt(d);c++)<br><span class="hljs-keyword">if</span>(d%c==<span class="hljs-number">0</span>) <span class="hljs-keyword">break</span>;<br><span class="hljs-keyword">if</span>(c&gt;sqrt(d))<br>printf(<span class="hljs-string">&quot;%d=%d+%d\n&quot;</span>,a,b,d);<br>&#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 85】<br>题目：判断一个素数能被几个 9 整除 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123; <span class="hljs-type">long</span> <span class="hljs-type">int</span> m9=<span class="hljs-number">9</span>,sum=<span class="hljs-number">9</span>;<br><span class="hljs-type">int</span> zi,n1=<span class="hljs-number">1</span>,c9=<span class="hljs-number">1</span>;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;zi);<br><span class="hljs-keyword">while</span>(n1!=<span class="hljs-number">0</span>)<br>&#123; <span class="hljs-keyword">if</span>(!(sum%zi))<br>n1=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">else</span><br>&#123;m9=m9*<span class="hljs-number">10</span>;<br>sum=sum+m9;<br>c9++;<br>&#125;<br>&#125;<br>printf(<span class="hljs-string">&quot;%ld,can be divided by %d \&quot;9\&quot;&quot;</span>,sum,c9);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 86】<br>题目：两个字符串连接程序 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">char</span> a[]=<span class="hljs-string">&quot;acegikm&quot;</span>;<br><span class="hljs-type">char</span> b[]=<span class="hljs-string">&quot;bdfhjlnpq&quot;</span>;<br><span class="hljs-type">char</span> c[<span class="hljs-number">80</span>],*p;<br><span class="hljs-type">int</span> i=<span class="hljs-number">0</span>,j=<span class="hljs-number">0</span>,k=<span class="hljs-number">0</span>;<br><span class="hljs-keyword">while</span>(a[i]!=<span class="hljs-string">&#x27;\0&#x27;</span>&amp;&amp;b[j]!=<span class="hljs-string">&#x27;\0&#x27;</span>)<br>&#123;<span class="hljs-keyword">if</span> (a[i] &#123; c[k]=a[i];i++;&#125;<br><span class="hljs-keyword">else</span><br>c[k]=b[j++];<br>k++;<br>&#125;<br>c[k]=<span class="hljs-string">&#x27;\0&#x27;</span>;<br><span class="hljs-keyword">if</span>(a[i]==<span class="hljs-string">&#x27;\0&#x27;</span>)<br>p=b+j;<br><span class="hljs-keyword">else</span><br>p=a+i;<br>strcat(c,p);<br>puts(c);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 87】<br>题目：回答结果（结构体变量传递） 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>struct student<br>&#123; <span class="hljs-type">int</span> x;<br><span class="hljs-type">char</span> c;<br>&#125; a;<br>main()<br>&#123;a.x=<span class="hljs-number">3</span>;<br>a.c=<span class="hljs-string">&#x27;a&#x27;</span>;<br>f(a);<br>printf(<span class="hljs-string">&quot;%d,%c&quot;</span>,a.x,a.c);<br>&#125;<br>f(struct student b)<br>&#123;<br>b.x=<span class="hljs-number">20</span>;<br>b.c=<span class="hljs-string">&#x27;y&#x27;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 88】<br>题目：读取 7 个数（1—50）的整数值，每读取一个值，程序打印出该值个数的＊。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<span class="hljs-type">int</span> i,a,n=<span class="hljs-number">1</span>;<br><span class="hljs-keyword">while</span>(n&lt;=<span class="hljs-number">7</span>)<br>&#123; <span class="hljs-keyword">do</span> &#123;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;a);<br>&#125;<span class="hljs-keyword">while</span>(a&lt;<span class="hljs-number">1</span>||a&gt;<span class="hljs-number">50</span>);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">1</span>;i&lt;=a;i++)<br>printf(<span class="hljs-string">&quot;*&quot;</span>);<br>printf(<span class="hljs-string">&quot;\n&quot;</span>);<br>n++;&#125;<br>getch();<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 89】<br>题目：某个公司采用公用电话传递数据，数据是四位的整数，在传递过程中是加密的，加密规则如下：<br>每位数字都加上 5,然后用和除以 10 的余数代替该数字，再将第一位和第四位交换，第二位和第三位交换。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java">main()<br>&#123;<span class="hljs-type">int</span> a,i,aa[<span class="hljs-number">4</span>],t;<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;a);<br>aa[<span class="hljs-number">0</span>]=a ;<br>aa[<span class="hljs-number">1</span>]=a <span class="hljs-number">0</span>/<span class="hljs-number">10</span>;<br>aa[<span class="hljs-number">2</span>]=a <span class="hljs-number">00</span>/<span class="hljs-number">100</span>;<br>aa[<span class="hljs-number">3</span>]=a/<span class="hljs-number">1000</span>;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">3</span>;i++)<br>&#123;aa[i]+=<span class="hljs-number">5</span>;<br>aa[i]%=<span class="hljs-number">10</span>;<br>&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">3</span>/<span class="hljs-number">2</span>;i++)<br>&#123;t=aa[i];<br>aa[i]=aa[<span class="hljs-number">3</span>-i];<br>aa[<span class="hljs-number">3</span>-i]=t;<br>&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">3</span>;i&gt;=<span class="hljs-number">0</span>;i--)<br>printf(<span class="hljs-string">&quot;%d&quot;</span>,aa[i]);<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>【程序 90】<br>题目：专升本一题，读结果。 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#define M <span class="hljs-number">5</span><br>main()<br>&#123;<span class="hljs-type">int</span> a[M]=&#123;<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>&#125;;<br><span class="hljs-type">int</span> i,j,t;<br>i=<span class="hljs-number">0</span>;j=M-<span class="hljs-number">1</span>;<br><span class="hljs-keyword">while</span>(i &#123;t=*(a+i);<br>*(a+i)=*(a+j);<br>*(a+j)=t;<br>i++;j--;<br>&#125;<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i <span class="hljs-title function_">printf</span><span class="hljs-params">(<span class="hljs-string">&quot;%d&quot;</span>,*(a+i)</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 91】<br>题目：时间函数举例 1 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>#include <span class="hljs-string">&quot;time.h&quot;</span><br><span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span><br>&#123; time_t lt; <span class="hljs-comment">/*define a longint time varible*/</span><br>lt=time(NULL);<span class="hljs-comment">/*system time and date*/</span><br>printf(ctime(&lt;)); <span class="hljs-comment">/*english format output*/</span><br>printf(asctime(localtime(&lt;)));<span class="hljs-comment">/*tranfer to tm*/</span><br>printf(asctime(gmtime(&lt;))); <span class="hljs-comment">/*tranfer to Greenwich time*/</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 92】<br>题目：时间函数举例 2 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*calculate time*/</span><br>#include <span class="hljs-string">&quot;time.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123; time_t start,end;<br><span class="hljs-type">int</span> i;<br>start=time(NULL);<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">3000</span>;i++)<br>&#123; printf(<span class="hljs-string">&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;</span>);&#125;<br>end=time(NULL);<br>printf(<span class="hljs-string">&quot;\1: The different is %6.3f\n&quot;</span>,difftime(end,start));<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 93】<br>题目：时间函数举例 3 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/*calculate time*/</span><br>#include <span class="hljs-string">&quot;time.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123; clock_t start,end;<br><span class="hljs-type">int</span> i;<br><span class="hljs-type">double</span> <span class="hljs-keyword">var</span>;<br>start=clock();<br><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">10000</span>;i++)<br>&#123; printf(<span class="hljs-string">&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;</span>);&#125;<br>end=clock();<br>printf(<span class="hljs-string">&quot;\1: The different is %6.3f\n&quot;</span>,(<span class="hljs-type">double</span>)(end-start));<br>&#125;<br></code></pre></td></tr></table></figure>

<p>【程序 94】<br>题目：时间函数举例 4,一个猜数游戏，判断一个人反应快慢。（版主初学时编的） 1.程序分析： 2.程序源代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs java">#include <span class="hljs-string">&quot;time.h&quot;</span><br>#include <span class="hljs-string">&quot;stdlib.h&quot;</span><br>#include <span class="hljs-string">&quot;stdio.h&quot;</span><br>main()<br>&#123;<span class="hljs-type">char</span> c;<br>clock_t start,end;<br>time_t a,b;<br><span class="hljs-type">double</span> <span class="hljs-keyword">var</span>;<br><span class="hljs-type">int</span> i,guess;<br>srand(time(NULL));<br>printf(<span class="hljs-string">&quot;do you want to play it.(&#x27;y&#x27; or &#x27;n&#x27;) \n&quot;</span>);<br>loop:<br><span class="hljs-keyword">while</span>((c=getchar())==<span class="hljs-string">&#x27;y&#x27;</span>)<br>&#123;<br>i=rand() <span class="hljs-number">0</span>;<br>printf(<span class="hljs-string">&quot;\nplease input number you guess:\n&quot;</span>);<br>start=clock();<br>a=time(NULL);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;guess);<br><span class="hljs-keyword">while</span>(guess!=i)<br>&#123;<span class="hljs-keyword">if</span>(guess&gt;i)<br>&#123;printf(<span class="hljs-string">&quot;please input a little smaller.\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;guess);&#125;<br><span class="hljs-keyword">else</span><br>&#123;printf(<span class="hljs-string">&quot;please input a little bigger.\n&quot;</span>);<br>scanf(<span class="hljs-string">&quot;%d&quot;</span>,&amp;guess);&#125;<br>&#125;<br>end=clock();<br>b=time(NULL);<br>printf(<span class="hljs-string">&quot;\1: It took you %6.3f seconds\n&quot;</span>,<span class="hljs-keyword">var</span>=(<span class="hljs-type">double</span>)(end-start)/<span class="hljs-number">18.2</span>);<br>printf(<span class="hljs-string">&quot;\1: it took you %6.3f seconds\n\n&quot;</span>,difftime(b,a));<br><span class="hljs-keyword">if</span>(<span class="hljs-keyword">var</span>&lt;<span class="hljs-number">15</span>)<br>printf(<span class="hljs-string">&quot;\1\1 You are very clever! \1\1\n\n&quot;</span>);<br><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-keyword">var</span>&lt;<span class="hljs-number">25</span>)<br>printf(<span class="hljs-string">&quot;\1\1 you are normal! \1\1\n\n&quot;</span>);<br><span class="hljs-keyword">else</span><br>printf(<span class="hljs-string">&quot;\1\1 you are stupid! \1\1\n\n&quot;</span>);<br>printf(<span class="hljs-string">&quot;\1\1 Congradulations \1\1\n\n&quot;</span>);<br>printf(<span class="hljs-string">&quot;The number you guess is %d&quot;</span>,i);<br>&#125;<br>printf(<span class="hljs-string">&quot;\ndo you want to try it again?(\&quot;yy\&quot;.or.\&quot;n\&quot;)\n&quot;</span>);<br><span class="hljs-keyword">if</span>((c=getch())==<span class="hljs-string">&#x27;y&#x27;</span>)<br>goto loop;<br>&#125;<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/C-C%E8%AF%AD%E8%A8%80/" class="category-chain-item">C++&amp;C语言</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>『C++&amp;C语言』C语言入门经典题目及其答案</div>
      <div>http://example.com/2023/12/06/『C++&amp;C语言』C语言入门经典题目及其答案/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Chiam</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年12月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8EC++&amp;C%E8%AF%AD%E8%A8%80%E3%80%8FC%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/" title="『C++&amp;C语言』C语言基础知识总结">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『C++&amp;C语言』C语言基础知识总结</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8EC++&amp;C%E8%AF%AD%E8%A8%80%E3%80%8FC++%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B%E7%B1%BB%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%AE%9A%E4%B9%89/" title="『C++&amp;C语言』C++面向对象编程类对象的定义">
                        <span class="hidden-mobile">『C++&amp;C语言』C++面向对象编程类对象的定义</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fIfc7WqUDZohlQuPc2lz5mJy-MdYXbMMI","appKey":"zjlAG3ZA3o4cBHVAkjzc2Z20","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://fifc7wqu.api.lncldglobal.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <meta name="referrer" content="no-referrer" /> <footer id="footer" role="contentinfo"> <div class="divider"> <div class="wall"></div> <img class="animals" src="/img/footer_animals_new.png" srcset="/img/loading.gif" lazyload alt="Footer Animals"> </div> <div class="container" data-index="450"> <p> <a href="https://chiamzhang.github.io" target="_blank">DogEgg</a> <i class="iconfont icon-love"></i> <a href="#" target="_blank">LittePig</a> </p> <p> Powered by  <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-pen"></i> Theme  <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> </p> </div> </footer> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="/js/love.js"></script>
<script src="/js/funnyTitle.js"></script>
<script src="/js/backTop.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"left","width":150,"height":150,"hOffset":20,"vOffset":0},"mobile":{"show":false,"scale":0.5},"react":{"opacity":0.9},"log":false});</script></body>
</html>
